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