PowerShell

PowerShell: Finding Built-In Cmdlets

In times where cmdlets can originate from all kinds of modules, it sometimes becomes important to find out which cmdlets are truly built into PowerShell and which represent external dependencies. One way of getting a list of built-in cmdlets is to temporarily open another runspace and enumerate its internal cmdlet list: $ps = [PowerShell]::Create() $ps.Runspace.RunspaceConfiguration.Cmdlets…

Continue Reading

PowerShell: Preserving Special Characters in Excel-generated CSV files

When you save Excel spreadsheets to a CSV file, special characters get lost. That’s because Excel is saving the CSV file using very simple ANSI encoding. The following line re-encodes the CSV file and uses UTF8 encoding, making special characters readable for Import-CSV: $Path = “c:\somepathtocsv.csv” (Get-Content $Path) | Set-Content $Path -Encoding UTF8

Continue Reading

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: 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: Finding Process Owners and Sessions

Get-Process returns a lot of information about running tasks but it does not return the process owners or the session a process is logged on to. There are built-in console tools like tasklist that do provide this information. By asking these tools to output their information as comma-separated values, PowerShell can pick up the information…

Continue Reading