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 ReadingPowerShell: Finding Object Properties
Sometimes, you know the information you are after is present in some object property, but there are so many properties that it is a hassle to search for the one that holds the information. In cases like this, you can convert the object to text lines, and then use Select-String to find the line (and…
Continue ReadingPowerShell: Finding IP Address
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…
Continue ReadingPowerShell: 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 ReadingPowerShell: Find Open Files
To find open files on a remote system, use openfiles.exe and convert the results to rich objects. Here is a sample (replace “comp1” with the name of a remote computer you have access permissions): PS> openfiles /Query /S comp1 /FO CSV /V | ConvertFrom-Csv | Out-GridView
Continue ReadingPowerShell: Creating Custom Objects
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,…
Continue Reading