Archive | October, 2012

PowerShell: Check Windows License Status

In PowerShell, you can directly access the raw licensing data like this: PS> Get-WmiObject SoftwareLicensingService You can also check the license status of your copy of Windows: PS> Get-WmiObject SoftwareLicensingProduct | Select-Object -Property Description, LicenseStatus | Out-GridView And you can find out which Windows SKU you are actually using: PS> Get-WmiObject SoftwareLicensingProduct | Where-Object { […]

Continue Reading →

PowerShell: Resetting Console Colors

If a console application or script has changed the console colors and you want to reset them to the default colors defined in your console properties, try this: PS> $host.ui.RawUI.ForegroundColor = ‘Red’ Now, the foreground color is red. Revert it back to standards: PS> [Console]::ResetColor() Note that this will work in a real console only. […]

Continue Reading →

PowerShell: Downloading Files from Internet

PowerShell v3 comes with a hugely useful new cmdlet called Invoke-WebRequest. You can use it to interact with websites which also includes downloading files. This will download the SysInternals suite of tools to your computer: $Source = ‘http://download.sysinternals.com/files/SysinternalsSuite.zip’ $Destination = “$env:temp\sysinternalssuite.zip” Invoke-WebRequest -uri $Source -OutFile $Destination Unblock-File $Destination Since downloaded files are blocked by Windows, […]

Continue Reading →

PowerShell: Listing Windows Updates

There is a not widely known COM object that you can use to list all the installed Windows Updates on a machine. Here is the code: $Session = New-Object -ComObject Microsoft.Update.Session $Searcher = $Session.CreateUpdateSearcher() $HistoryCount = $Searcher.GetTotalHistoryCount() $Searcher.QueryHistory(1,$HistoryCount) | Select-Object Date, Title, Description

Continue Reading →

PowerShell: Displaying Balloon Tip

Let’s assume your script wants to share status information via a balloon message in the system tray area. Here is a sample: [system.Reflection.Assembly]::LoadWithPartialName(‘System.Windows.Forms’) | Out-Null $balloon = New-Object System.Windows.Forms.NotifyIcon $path = Get-Process -id $pid | Select-Object -ExpandProperty Path $icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) $balloon.Icon = $icon $balloon.BalloonTipIcon = ‘Info’ $balloon.BalloonTipText = ‘Completed Operation’ $balloon.BalloonTipTitle = ‘Done’ $balloon.Visible […]

Continue Reading →

PowerShell: Extracting Icons

To extract an icon from a file, use .NET Framework methods. Here is a sample that extracts all icons from all exe files in your Windows folder (or one of its subfolders) and puts them into a separate folder: [System.Reflection.Assembly]::LoadWithPartialName(‘System.Drawing’) | Out-Null $folder = “$env:temp\icons” md $folder -ea 0 | Out-Null dir $env:windir *.exe -ea […]

Continue Reading →

PowerShell: Clean Your Temp Folder

When disk space gets low, you may want to clean up your temporary folder. The code deletes all files that are older than 30 days to make sure you’re not dumping anything that’s still needed: $cutoff = (Get-Date) – (New-TimeSpan -Days 30) $before = (Get-ChildItem $env:temp | Measure-Object Length -Sum).Sum Get-ChildItem $env:temp | Where-Object { […]

Continue Reading →

PowerShell: Appending CSV Data

To append a CSV file with new data, first of all make sure the type of data you append is the same type of data already in a file (or else column names will not match). This creates a list of unique running processes (so it will not list duplicate process names): $filepath = “$env:temp\processes.csv” […]

Continue Reading →
revia in alcoholism