Try this if you need to check a single character and find out whether or not it is numeric: PS > [char]::IsNumber('1') True PS >...
powertips
Check Array Content With Wildcards
You may know the -contains operator. Try using it to check whether an array contains a specific element: PS > $names = dir $env:windir |...
Adding New PowerShell Drives
You can add a bunch of interesting new drives to PowerShell with just a single line of code:...
Re-Assigning Types to Variables
You can no longer assign other types when you strongly type a variable: [Int]$a = 1 $a = 'does not work' However, you can always...
Generate Random Passwords
In a previous tip, we showed you how to create random passwords. Thanks to your feedback, here is an even shorter version: -join...
Tile Windows
Do you remember the ancient feature where you could tile or cascade all open windows? These features are still available. However, before you try...
Case-Sensitive Hash Tables
PowerShell hash tables are, by default, not case sensitive: PS > $hash = @{} PS > $hash.Key = 1 PS > $hash.keY = 2 PS > $hash.KEY 2 If...
Creating Byte Arrays
You can try this to create a new empty byte array with 100 bytes: $byte = New-Object Byte[] 100 Try this if you need to create a byte array...
Quickly Changing File Extensions
If you want to quickly exchange a file extension to create a "bak" backup version or generate a new file name for output, you should use...
Grouping Files Based On Size
In a previous tip, we showed you how to group using your own criteria. Group-Object can also auto-create hash tables so that you can easily create...
Grouping Using Custom Criteria
Try using Group-Object to group objects by any property: PS> Get-Process | Group-Object -property Company You can also submit a script block and...
Parsing Text-Based Log Files – Faster!
In a previous tip, we showed you how to parse text-based log files using the PowerShell pipeline. However, the pipeline has considerable overhead....
Parsing Text-Based Log Files
Extracting useful information from huge text-based log files isn’t necessarily a difficult task. Check out this line: PS> Get-Content...
Finding IP Addresses
Sometimes, classic tools like ipconfig.exe can yield useful information that you'd like to integrate with PowerShell. Here is sample code that...
Calculate Total Folder Size
Here is a useful function that you can use to calculate the total size of a folder: function Get-FolderSize($path) { Get-ChildItem $path -Recurse...
Use WMI to Create Hardware Inventory
You can use Get-WMIObject to create a high-level hardware report. Instead of submitting a specific device class name, you should use a generic...
Remove Keys From a Hash Table
Once you create a hash table, it is easy for you to add new key-value pairs like this: PS > $myHash = @{} PS > $myHash.Name = 'Tobias'...
Copy Registry Hives
You can use Copy-Item to quickly copy entire structures of registry keys and sub-keys in a matter of milliseconds. Take a look at this example...
Getting Full Admin Privileges
You may sometimes get "Access Denied" exceptions, even though you have Admin privileges and used an elevated shell. For ...
RegEx Magic
The [RegEx] type has a method called Replace(), which can be used to replace text by using regular expressions. This line would replace the last...
Find Dependent Services
If you would like to check the implications of stopping a service, you should have a look at its dependent services: (Get-Service...
Restart required
Check out this line to determine when an installation required a system restart: Get-EventLog -InstanceId 1038 -LogName Application | ForEach-Object...
Finding multiple RegEx matches
In a previous tip, you learned that Select-Object can find multiple matches. Here is a function called matches. You can submit a regular expressions...
Find multiple matches
When you want to find matches based on regular expressions, PowerShell will only support the -match operator which finds the first match. There does...