[System.Security.Principal.SecurityIdentifier _i="0" _address="0" theme_builder_area="post_content" /][System.Security.Principal.NTAccount _i="1"...
ps1
SID of Current User
Here is a one-liner that returns the SID for the current user and can be used in logon scripts, for example:...
Scanning Ports
Here is a straightforward way to test ports on a local or remote system. You can even specify a timeout (in milliseconds): function Get-PortInfo {...
Resetting Console Colors
It can be easy to mess up console colors in the PowerShell console. A single call with accidental values, or a script that messed with the colors,...
Solving SSL Connection Problems
Sometimes when you try to access web services (or download internet content in general), PowerShell may bail out and complain about not being able...
Deleting the Oldest Log File
Enable Real-Time Streaming with Foreach
Classic foreach loops are the fastest loop available but they come with a severe limitation. Foreach loops do not support streaming. You need to...
Listing Network Drives
There are many ways to create a list of network drives. One involves a COM interface that was used by VBScript as well, and we’ll pick it to...
Sending Emails via Outlook
You can always use Send-MailMessage to send a mail via any SMTP server. If you’d like to use your Outlook client, though, i.e. to keep access...
Title-Casing Strings (Capital Letter Starts Each Word)
Polishing raw text is not always trivial, and when you’d like to make sure names or texts are well-formed, and each word starts with a capital...
Concatenating Text Files
Finding Windows Universal Unique Identifier (UUID)
Every Windows installation has a unique UUID that you can use to distinguish machines. While computer names can change, the UUID won’t: PS>...
Formatting Date and Time (with Culture)
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...
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...