Try this one-liner if you need to print out all PDF documents you have stored in one folder: Dir c:\myfolder\*.pdf | Foreach-Object { Start-Process...
Powershell
Store Pictures in Active Directory
When you need to store a picture into an AD account, the picture will have to be converted to byte values before it can be stored. Just make sure...
Finding IP and MAC address
When you query network adapters with WMI, it is not easy to find the active network card. To find the network card(s) that are currently connected...
Turning Multi-Value WMI Properties into Text
When you read multi-valued information from WMI or any other source, for example, network adapter IP addresses, this information is returned as a...
Finding Network Adapter Data Based On Connection Name
Sometimes it would be nice to be able to access network adapter configuration based on the name of that adapter as it appears in your network and...
Creating Excel Reports from PowerShell Data
Provided you have Microsoft Excel installed, here is a clever function that you can use to convert PowerShell results into Excel spreadsheets:...
Outputting Text Reports without Truncating
If you want to capture PowerShell results in a text file, you can redirect the results or pipe them to Out-File. In any case, what you capture is...
Turning SIDs into Real Names
Sometimes, you'd like to turn security identifiers (SIDs) into real names. Here is a function that can do this for you: function SID2Name($sid){...
Converting User Names to SIDs
If you want to translate a valid user name to its security identifier (SID), here is a function to do that for you: function Name2SID($name,...
Changing Units
When you list folder contents, file sizes are in bytes. If you'd rather like to view them in MB or GB, you can use calculated properties, but by...
Closing Excel Gracefully
When you access Microsoft Excel from script, you may have noticed that it never gets removed from memory again, even if you call its Quit() method:...
Formatting Currencies
Formatting numbers as currencies is straight-forward - as long as it is your own currency format: '{0:C}' -f 12.22 If you want to output...
Using Regular Expressions with Dir
When you use Dir (alias: Get-ChildItem) to list folder contents, you can use simple wildcards but they do not give you much control. A much more...
Permanently Changing User Environment Variables
To create or change an environment variable in the user context, use this low-level call: [environment]::SetEnvironmentVariable('Test',...
Using Wildcards with Environment Variables
You can use the env: PowerShell drive to list all Windows environment variables like this: PS> Dir env:*user* Name Value ---- ----- USERNAME...
Creating PowerShell Menus
PowerShell is console based, so its default menus are console based as well. To offer choices to your users, here is some sample code to create a...
Scanning Registry for ClassIDs
The Windows Registry is a repository filled with various Windows settings. Get-ItemProperty can read Registry values and accepts wildcards. So, with...
Bypassing Execution Policy
When execution policy prevents execution of PowerShell scripts, you can still execute them. There is a secret parameter called "-" . When you use...
Controlling Automatic Updates Installation Time
To find out when Automatic Updates wakes your PC to install new updates, here is a script that will retrieve that information: $updateObj =...
Controlling Automatic Updates
To control whether Windows download and/or installs updates silently or prompts for permission, use this script and set the appropriate...
Retrieve Yesterday’s Error Events
To retrieve all error events from a system log that occurred yesterday, here is how to calculate the start and stop times: PS> $end = Get-Date...
Creating Intelligent Variables
To create variables that calculate their content each time they are accessed, use access-triggered variable breakpoints. This line, for example,...
Setting Breakpoints in PowerShell Scripts
Most sophisticated PowerShell editors have built-in debugging support. PowerShell can handle breakpoints natively, too, though. To make PowerShell...
PowerShell Script Security Auditing
When you digitally sign scripts, you can easily tell whether a script was manipulated or comes from an untrusted source. Here is a function that can...