Maybe you are happy with other scripting languages, like VBScript, and would like to stick to that for awhile. Still, you'd like to enhance your...
database-tools
Launching Files with Arguments
Often, you want to submit additional arguments to a program file when you launch it, such as you want to open IE and have it navigate to some Web...
Launching Files with Spaces
What if you'd like to launch a file with spaces in its path? The first rule is that spaces are separators, so PowerShell would separate it at...
Launching Files without Specifying a Path
For security reasons, PowerShell launches files only when specified with a relative or absolute path name. The only exceptions to this rule are...
Launching Files
The most important rule: always specify either an absolute or relative file path to whatever you want to launch - except if the file is located in a...
Getting Real Paths
PowerShell uses virtual drives, which sometimes have a close mapping to the "real" drives you see in Windows Explorer. However, sometimes...
Deleting Things
To delete things in the file system, you normally use a command like "del", which is an alias and points to Remove-Item in PowerShell:...
Append Information to Text Files
Add-Content is a versatile command if you need to add additional content to text files. For example, you can create log file entries like this:...
Secret -Force Switch
PowerShell automatically displays all object properties when you output the object to the console. Here is an example: Get-WmiObject win32_bios...
Returning Exit Code from Script
When running a PowerShell script, you may want to return a numeric exit code to the caller to indicate failure or success. You should use the...
List Local Groups
If you'd like to get a list of all local Groups on your computer, you can use this line: Get-WMIObject Win32_Group -filter...
List All Group Memberships of Current User
In case you need to get a list of all of your current Group memberships as derived from your current access token, use this line:...
Working Remotely With WMI
PowerShell v1 has no support for working remotely but WMI natively is able to work on local or remote machines. Simply use the -computername...
Deleting Shares
If you'd like to get rid of a file share, such as the one you created via WMI in our last tip, this is how you can do it: (Get-WMIObject...
Creating New Shares
You can use WMI to help create new file shares. This is the line you need: md...
Renaming Object Properties
You can use Select-Object to rename existing object properties. For example, you would like to rename e a directory listing "Name"...
Finding CD-ROM Drives
You can find out whether a system has CD-Drives by using a little function that returns all drive letters from all CD Drives in your system:...
Cloning Objects
As a rule of thumb, PowerShell creates real copies when you copy variables. So in the next example, changing the array in $a will not affect the...
Combining PowerShell And VBScript
PowerShell has a great way of integrating existing VBScripts. All you need to do is call the script using the console-based host cscript.exe. Then,...
Expanding Group Results
Group-Object is perfect for grouping objects based on one or more properties. Once you group objects, you can then filter, or sort, based on their...
Create Text Reports with Format-Table
Format-Table is a great cmdlet to output formatted data. Sometimes, you may just be interested in the raw table data. You can simply hide the column...
Sort With PS Code
Sort-Object is a great and versatile cmdlet to sort anything you want. Simply specify the property or properties you want to use for sorting: Dir...
Displaying First Or Last Elements
Select-Object can limit results to only the first or last elements. Simply use -first or -last: dir | select-object -first 10Get-Process |...
Splitting Text Into Words
If you ever need to read in a file and split file content into words, there are a couple of gotchas to keep in mind. First off, remember that...