Most PowerShell functions use static parameters. They are defined in a param() block and are always present. A little-known fact is that you can...
powertips
Accessing Website Content
Typically, it is trivial for PowerShell to retrieve raw HTML website content by using Invoke-WebRequest. A script can then take the HTML content and...
Accepting Different Parameter Types
Occasionally, you might want to create a function that accepts different parameter types. Let’s say you want the user to be able to either submit an...
Translating VBScript to PowerShell
Most old VBS scripts can be easily translated to PowerShell. The key command in VBS is “CreateObject” which lets you access system libraries....
Invoking Excel Macros from PowerShell
PowerShell can invoke Microsoft Excel sheets and start contained macros. While this would work with an invisible Excel application window, it is a...
Programmatically listing any Cmdlet or Function Parameters
Ever wondered how you can list all properties exposed by a function or cmdlet? Here is how: Get-Help Get-Service -Parameter * | Select-Object...
Examining Object Properties Programmatically
Whether you import a CSV list into PowerShell using Import-Csv, or deal with any other type of objects: how can you automatically determine the...
Accessing Hidden (Private) Member
[System.Management.Automation.ModuleIntrinsics _i="0" _address="0.0.0.0" theme_builder_area="post_content"...
Performance (Part 3): Faster Pipeline Functions
In previous tips we illustrated how you can improve loops and especially pipeline operations. To transfer this knowledge to functions, take a look...
Performance (Part 2): From 2 sec to 200ms
In the previous tip we added considerable speed to a common script pattern. Now, let’s squeeze out even more performance with a pretty unusual...
Performance (Part 1): From 6 min to 2 sec
Here is a common mistake found in many PowerShell scripts: $start = Get-Date $bucket = @() 1..100000 | ForEach-Object { $bucket += "I am adding...
Keeping Track of Script Execution
Here is a chunk of code that demonstrates how you can store private settings in the Windows Registry: # store settings here $Path =...
Retrieving Outlook Calendar Entries
If you use Outlook to organize your calendar events, here is a useful PowerShell function that connects to Outlook and dumps your calendar entries:...
Getting AD Users with Selected First Letters
How would you query for all AD users with names that start with a “e”-“g”? You shouldn’t use a client-side filter such...
Adding New Incrementing Number Column in a Grid View Window
Maybe you’d like to add a column with incrementing indices to your objects. Try this: $startcount = 0 Get-Service | Select-Object -Property...
Improving Group-Object
In the previous tip we explained what Group-Object can do for you, and how awesome it is. Unfortunately, Group-Object does not scale well. When you...
Discover Group-Object
Group-Object is an awesome cmdlet: it can easily visualize distributions. Check out the examples below: Get-Process | Group-Object -Property Company...
Automating “Live” Websites
Occasionally, there is the need to automate tasks on websites that have been opened manually. Maybe you need to log into internal web pages first...
Installing Printers
Starting with Windows 8 and Server 2012 R2, these operating systems ship a PowerShell module called PrintManagement. The cmdlets found in this...
Using CSV to Create Objects
Sometimes it may be clever to use simple text-based CSV format internally to bulk-create objects, especially if the original data is already...
Finding Active Directory Group Members Efficiently
Often, AD Administrators need to find all members of a given AD group, including nested members. Here is a code snippet that frequently surfaces in...
Using Artificial Intelligence with Azure Cognitive Services
The cloud these days not only offers virtual machines and storage, but also brand new and exciting services such as the cognitive services. You need...
Backing Up All Scripts to ZIP
PowerShell 5 finally includes support for ZIP files, so if you want to backup all of your PowerShell scripts into one ZIP file, here is a one-liner:...
Running PowerShell Code as Someone Else
Local admin privileges are extremely powerful, and you should use techniques such as JEA to minimize the number of local Admins as much as you can....