You can use $null as a special variable representing "nothing." You can use it to identify (and sort out) non-existing data like so:...
database-tools
Use Write-Progress to Return Feedback
Some operations will take more time so it is a good idea to return feedback. Write-Progress can do just that. Go ahead and add a Foreach-Object to...
Sending POST Data via PowerShell
Often, feedback or votes on Web pages are sent back via POST requests. You can send this kind of information via PowerShell as well. You should...
Connect or Disconnect Network Adapter
When you are ready to connect or disconnect a network adapter, you can utilize the Shell.Application COM object, which will give you access to...
Finding 10 Largest Files
You may need to find the largest files for possible clean-up when free space on a drive runs low. One way is to have PowerShell examine all file...
Random Tip of the Day
Get-Random has a dual purpose. It can provide you with a random number and also pick random elements from a collection. So, if you want to get a new...
Sorting Stuff
You can use Sort-Object to sort simple variable types. Have a look at the following: 'Tom', 'Chris', 'Judy', 'Alan'...
Finding Invalid Aliases
When you create new Aliases with Set-Alias, PowerShell does not check whether the target you specify is valid. Instead, this is checked only when...
IPv4 Address Lists
You should try this to get all IPv4 addresses assigned to your system: Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled...
Getting Assigned IP Addresses
You should use this to retrieve all IP addresses assigned to your computer: Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object...
Generate PC Lists
One easy way of creating lists of PC names or IP address ranges etc is a simple pipeline like this: 1..40 | Foreach-Object {...
Create HTA Files
Another way is to ConvertTo-HTML is a convenient way of converting object results in HTML. However when you open these files, your browser starts...
WMI Server Side Filtering
Whenever you use Get-WMIObject, be sure to minimize resources and maximize speed by using server-side filtering. The next line will use the slow...
List Installed Updates
Using Get-Hotfix is pretty convenient as it serves to list installed updates. Unfortunately, it is not very thorough as it doesn’t retrieve...
Downloading Files Silently in the Background
When using the additional cmdlets in the BitsTransfer module that comes with Windows 7 and Server 2008 R2, you can make downloads happen silently in...
Download Files from the Internet
Windows 7 and Server 2008 R2 come with a module called BitsTransfer, which allows you to access the background intelligent transfer service used by...
Adding New Snapins and Modules
Snapins and modules can add new cmdlets and/or providers to PowerShell. Use this if you would like to see the list of available Snapins:...
Test whether Registry Value exists
You should remember that registry values are treated like properties to a registry key so they have no specific path and you cannot use Test-Path to...
Test whether Registry Key exists
If you would like to test whether a certain registry key exists, you should remember that all registry keys are treated like folders on a drive, so...
Creating Constant Functions
In PowerShell, functions can be constant to prevent them from being deleted anymore, which is necessary if you must protect security-critical...
Adding Protection to Functions
Functions that you define are read/write and can easily be overwritten. You can set the read-only attribute to make a function read-only so that you...
Reading Default Values
Each registry key has a default value. It is called (default) when you look into regedit. To read this default value, you can just use this name...
List Installed Software
Get-ItemProperty reads registry values. You can create a software inventory in just one line since it supports wildcards: Get-ItemProperty...
Read Registry Values
You will find that reading Registry values is not always easy because the Registry is accessible only via the generic "drive" paradigm....