In the previous tip we illustrated how Get-Date can take a format string and convert DateTime values to strings. The string conversion always uses...
posts-powershell
Formatting Date and Time
Formatting date and time to your needs is easy with the -Format parameter provided by Get-Date. You can use it either with the current date, or...
Sending PowerShell Results to PDF (Part 4)
In the previous tip we created the function Out-PDFFile which accepts any PowerShell results and turns them into a PDF file – using the built-in...
Sending PowerShell Results to PDF (Part 3)
In the previous tip we explained how you can use PowerShell on Windows 10 and Windows Server 2016 to set up a PDF printer that prints anything to a...
Sending PowerShell Results to PDF (Part 2)
In the previous tip we illustrated how you can use the built-in “Microsoft Print to PDF” printer to send PowerShell output to PDF files. However,...
Sending PowerShell Results to PDF (Part 1)
Windows 10 and Windows Server 2016 finally come with a built-in PDF printer called “Microsoft Print to PDF” that you can use from...
Printing Test Pages on Printers
Windows 10 and Windows Server 2016 come with extensive printer support thanks to the PrintManagement module. If you’d like to print official...
Using FileSystemWatcher Correctly (Part 2)
In the previous tip we introduced the FileSystemWatcher and illustrated how it can miss filesystem changes when your handler code takes too long. To...
Using FileSystemWatcher Correctly (Part 1)
A FileSystemWatcher can monitor a file or folder for changes, so your PowerShell code can immediately be notified when new files are copied to a...
Responding to New Event Log Entries (Part 2)
Here is another file system task that sounds worse than it actually is. Let’s say you need to remove all folders below a given level in a...
Responding to New Event Log Entries (Part 1)
If you’d like to respond to new event log entries in real time, here is how your PowerShell code can be notified the moment a new event entry...
Accessing Event Logs Directly
With Get-EventLog, you can easily dump the content for any given event log, however if you’d like to directly access a given event log, you...
Using a Stop Watch
In PowerShell, to measure time, you can simply subtract datetime values from another: $Start = Get-Date $null = Read-Host -Prompt "Press ENTER...
Using Solid Alternatives for $MyInvocation
Lines like $MyInvocation.MyCommand.Definition can be useful to determine the folder in which the current script is stored, i.e. to access other...
Finding Open Firewall Ports
Here is a piece of PowerShell code that connects to the local firewall and dumps the open firewall ports: $firewall = New-object -ComObject...
Executing Code with a Timeout (Part 2)
In the previous tip we implemented a timeout using PowerShell background jobs so you could set a maximum time some code was allowed to run before it...
Executing Code with a Timeout (Part 1)
If you’d like to make sure some code won’t execute forever, you can use background jobs to implement a timeout. Here is a sample...
Code-Signing Mini-Series (Part 5: Auditing Signatures)
Once a PowerShell script carries a digital signature, you can easily find out who signed the script, and more importantly, whether the script is...
Code-Signing Mini-Series (Part 4: Code-Signing PowerShell Files)
Before you give away a PowerShell script to others, it is a good idea to digitally sign it. A signature acts like a “wrapper” for your...
Code-Signing Mini-Series (Part 3: Reading Certificates from Personal Store)
Certificates can be installed permanently by loading them into Windows certificate store. PowerShell can access this store via its cert: drive. The...
Code-Signing Mini-Series (Part 2: Reading Certificates from PFX Files)
In the previous tip we created new code-signing test certificates both as pfx file and located in your certificate store. Today, you’ll see...
Code-Signing Mini-Series (Part 1: Creating Certs)
To play with digital signatures, and discover how you can sign scripts and modules, you first need a code-signing certificate. If you can’t get one...
Converting SecureString to Clear Text
Secure string content cannot be easily viewed: $password = Read-Host -Prompt 'Your password' -AsSecureString PS C:\> $password...
Using Catalog Files
Catalog file support (.cat) is new in PowerShell 5.1. Cat files basically are file lists with hash values. You can use them to ensure that a given...