In the previous tip we looked at command extensions for the good old PowerShell ISE. Here is another sample that adds the CTRL+K keyboard shortcut...
powertips
Toggling Comments in PowerShell ISE
The good old PowerShell ISE exposes some expandability connectors. If you’d like to toggle comments in selected text by pressing CTRL+K, for...
Converting Hash Tables to JSON
In previous scripts we worked a lot with hash tables, and even loaded them from .psd1 files. If you need the data in a different format, for example...
Reading Data from .PSD1 Files in PowerShell 5+
In a previous tip we introduced Import-LocalizedData to read in data stored in a .psd1 file. Starting in PowerShell 5, there is a new cmdlet named...
Reading Data from .PSD1 Files
There are many ways how a script can store data information. One is especially convenient. Here is the code: Import-LocalizedData -BaseDirectory...
Understanding .NET Type Name Variants in PowerShell
PowerShell can use .NET type names, for example to convert values to a given type. Frequently, scripts use a variety of formats to define .NET...
Minimalistic Error Handling
Error handling does not necessarily have to be complex. It can be as simple as checking whether the last command executed successfully: # suppress...
Temporarily Disabling PSReadLine Module
Beginning in PowerShell 5, the PowerShell console features colorized text, and there is a wealth of other new features provided by a module named...
Using Windows EventLog for Script Logging
Getting File Extension
By converting a path to a FileInfo object, you can easily determine the path parent folder or file extension. Have a look:...
Working with [FileInfo] Object
Often, code needs to check on files, and for example test whether the file exists or exceeds a given size. Here is some commonly used code: $logFile...
Script Logging Made Easy
Beginning in PowerShell 5, you can use Start-Transcript in any host to log all the output created by your script. Here is how you can easily add...
Multi-Language Voice Output
On Windows 10, the operating system ships with a bunch of high-quality text-to-speech engines and is no longer limited to just the English language....
Removing Text from Strings
Occasionally, you might read about Trim(), TrimStart(), and TrimEnd() to remove text from strings. And this seems to really work well: PS C:\>...
Uncompressing Serialized Data
In the previous tip you learned how you can use Export-CliXml to serialize data and then use Compress-Archive to shrink the huge XML files to only a...
Compressing Serialized Data
Multipass: Securely Storing Multiple Credentials
If you’d like to safely store credentials (usernames and password) for your personal use in a file, here is a very simple yet extremely...
A Better (and Faster) Start-Job
Start-Job transfers a script block to a new PowerShell process so that it can run separately and in parallel. Here is a very simple sample...
Using Digital Signatures with Timestamp Server
When you start signing script files, you want to make sure signatures stay intact even if the certificate that signed it expires at some day in the...
Digitally Signing PowerShell Scripts
In the previous tips you learned how you can create a self-signed code signing certificate, save it to a PFX file, and read it back into memory....
Loading Certificates from PFX Files
In the previous tip we illustrated how you can use New-SelfSignedCertificate to create new code signing certificates, and store them as a PFX file....
Creating Self-Signed Code Signing Certificates
If you’d like to digitally sign your scripts, the first thing you need is a digital certificate with the designated purpose set to “Code...
Using LDAP Filters in Active Directory
LDAP filters resemble the query language used by Active Directory, and if you have installed Microsoft’s RSAT tools, you can easily use the...
Comparing Computer Data Received from PowerShell Remoting
PowerShell remoting is a very fast way to query multiple computers because PowerShell remoting works in parallel. Here is a real world use case that...