PowerShell: Finding Built-In Cmdlets

Posted Leave a commentPosted in PowerShell

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 […]

PowerShell: Finding IP Address

Posted 1 CommentPosted in PowerShell

There are various ways to determine the IP address that is assigned to your machine. Here is a rather unusual approach that uses text operators to filter the information out of the results provided by ipconfig.exe. This is not the most solid way of getting to an IP address. It is, however, an interesting brain […]

PowerShell: Preserving Special Characters in Excel-generated CSV files

Posted Leave a commentPosted in PowerShell

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

PowerShell: Creating Custom Objects

Posted Leave a commentPosted in PowerShell

If you want to create your own custom objects, for example, to enable your functions to return rich objects, you can always use Select-Object like this: PS> $newobject = ‘dummy’ | Select-Object -Property Name, ID, Address Then, you can fill in the properties and use the object: PS> $newobject = ‘dummy’ | Select-Object -Property Name, […]

PowerShell: Check Windows License Status

Posted Leave a commentPosted in PowerShell

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 { […]

PowerShell: Resetting Console Colors

Posted Leave a commentPosted in PowerShell

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. […]

PowerShell: Downloading Files from Internet

Posted 1 CommentPosted in PowerShell

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, […]