PowerShell internally always works with objects, and this can cause confusion when you mix object and string technologies. In a previous example,...
Powershell
Listing All Installed Font Families
To get a list of all available font families on your system, you can load the .NET drawing library and then ask the InstalledFontCollection for all...
Finding Empty Folders
To find out all folders that contain no files, you can use this line: dir -recurse | Where-Object { $_.PSIsContainer } | Where-Object {...
List All Folders and Subfolders
Ever wanted to create a list of all folders and subfolders? It just takes one line: dir -recurse | Where-Object { $_.PSIsContainer } |...
List Hidden Files
Did you notice that Dir, ls or Get-ChildItem do not return hidden files? To see hidden files, you need to specify the -force parameter: Dir...
Converting FileSystem To NTFS
When you buy a new external USB drive, most of the time it is preformatted with the old FAT32 file system for compatibility reasons. You could...
Reading and Writing Drive Labels
Drive Labels are the names attached to logical disks. Using WMI, you can both read and write (change) drive labels. To read the existing drive...
Finding Out A Drives’ FileSystem
If you ever needed a tool to find out the type of file system for any drive, take a look at this simple PowerShell function: function...
Feeding Input Into Native Commands
Sometimes, you need to call commands that require interactive input to work. For example, to find out existing drives with DiskPart, you would have...
Advanced String Filtering
In a previous tip, you learned how Select-String can filter string arrays based on a keyword. Have a look: route print | Select-String 127.0.0.1...
Filtering Command Results
PowerShell captures any output from any command you enter. This is why you can always store command results in a variable, even with native...
"Grep": Finding PowerShell Scripts with a Keyword
Select-String can automatically search entire folders and scan all file contents for specific key words. All you do is to provide a path to scan,...
Using Select-String to Focus on the important stuff
Select-String is a fun cmdlet. Whenever a command returns string data, Select-String filters out text that does not contain a specific keyword. For...
Wait For Key Press
Sometimes you'd like to wait for a key press. The easiest way is to use Read-Host like this: Read-Host 'Please press ENTER' | Out-Null...
Consolidating Information In An Object
Sometimes, you may want to store information you gathered in different places into one single object and return this object to the caller. This is...
Displaying Battery Charge in your prompt
If you use a notebook and are on the road often, you may want a way to check the battery status so you can shut down your stuff in time. Here is a...
Summing Up Multiple Objects
PowerShell is a dynamic language, and as Forest Gump put it, you never know what you get. For example, when you try and figure out the battery...
Adding Multiple Registry Keys
With New-Item, it is easy to create new registry keys: New-Item HKCU:SoftwareTestkey New-Item can only create one key at a time and fails if the...
Virtual Drives With UNC-Paths
With New-PSDrive, you can create new virtual PowerShell drives to locations you often visit. New-PSDrive needs three pieces of information: the name...
Assigning Values to Parameters
Cmdlets and Functions most of the time support one or more parameters. Let's take this simple function. It defines two parameters called number and...
Avoid Format-… in Scripts
The family of Format-... Cmdlets is useful for outputting data into the console. You probably often used lines like this: Get-Service | Format-Table...
Using Switch Parameters
Switch parameters work like a switch, so they are either "on" or "off" aka $true or $false. To add a switch parameter to a...
Conflicting Commands
PowerShell supports many different command categories and searches for the command in the following order: 1. Alias 2. Function 3. Cmdlet 4....
Extending Alias Functionality
Alias names are a good way of making commands more accessible. The following line would enable you to quickly launch Internet Explorer by entering...