In a previous tip we explained that in PowerShell 3.0, every object has a Count property now. This even includes null values: PS> $null.Count 0...
Powershell
Displaying Object Standard Properties (Nicely)
In a previous tip, we explained how you can add a custom data type to your own custom objects that you might want to return from a function, and...
"Count" Available in PowerShell 3.0
Finally, the property Count is available on all objects in PowerShell 3.0. This solves a great problem because it allows you to count results even...
Removing Empty Object Properties (All Versions)
In a previous tip we showed how you can remove all empty properties from an object and also sort its properties alphabetically. The code required...
Removing Empty Object Properties
Objects hold a lot of information and often, properties can also have null values. To reduce an object to only those properties that actually have a...
Controlling Object Property Display
When you create functions that return custom objects, there is no way for you to declare which functions should display by default. PowerShell...
Logging Input Commands
If you'd like to maintain a log file with all the commands you entered interactively - in the PowerShell console as well as in the ISE editor -...
Creating Objects in PowerShell 3.0 (Fast and Easy)
In PowerShell 3.0, you can cast a hash table to a PSCustomObject type to easily generate your own objects: $content = @{ Name="Weltner"...
Protecting Functions
To prevent a function to be redefined or overwritten, you can write-protect it: function Test-Function { 'Hello World!' } Set-Item -Path...
Creating New Objects the JSON way
There are numerous ways how you can create new objects that you may use to return results from your functions. One way is using JSON, a very simple...
WhatIf-Support Without Propagation
You can enable the -WhatIf and -Confirm parameters in your functions too, and control which parts of your code get skipped if the user specifies...
Finding Enumeration Data Types
In a previous tip you learned that assigning an enumeration data type to a function parameter automatically enables argument completion in...
Using Enumeration Types for Parameter IntelliSense
In a previous tip you learned how decorating function parameters with a ValidateSet attribute would allow the ISE editor to display intelliSense...
Rich IntelliSense for Function Arguments
To take advantage of the new PowerShell 3.0 argument completion, make sure you're adding ValidateSet attribute to your function parameters...
Get-WmiObject Becomes Obsolete
In PowerShell 3.0, while you still can use the powerful Get-WmiObject cmdlet, it is slowly becoming replaced by the family of CIM cmdlets. If you...
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...
Providing "Static" IntelliSense for Your Functions
To get rich IntelliSense in PowerShell ISE 3.0, you should start adding the OutputType attribute to your functions. If you do, then ISE is able to...
Detecting STA-Mode
Here is a simple line that tells you whether PowerShell runs in MTA- or STA-mode: [Runspace]::DefaultRunspace.ApartmentState -eq 'STA' This...
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...
Finding Object Properties in Powershell
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...
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...
Change Order of CSV Columns
If you have a CSV file and would like to change the order of columns, simply import it into PowerShell, use Select-Object to change the order, and...
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 "storage1"...
Creating Custom Objects 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...