Provided you have Administrator privileges, you can use a simple WMI class to check whether someone is accessing your resources via the network:...
Powershell
Disable Automatic Reboot After Update
Are you tired of Windows unexpectedly rebooting, just because some newly installed updates required a reboot? Like most things, you can control the...
Removing Whitespace (and Line Breaks)
You may know that each string object has a method called Trim() that trims away whitespace both from the beginning and end of a string: $text =...
Receiving Error Level from PowerShell Script
Here is a quick script illustrating how a PowerShell script can send back a numeric status code to the caller: $exitcode = 123 $p = Start-Process...
Why "exit" can kill PowerShell
Occasionally, there are misunderstandings how "exit" works. Take this example: function abc { 'Start' exit 100 'Done' }...
Understanding break, continue, return, and exit
Do you know off-hand what "break", "continue", "return", and "exit" do? These are powerful language...
Identifying Risky NTFS Permissions
Here is a quick and easy way to find NTFS permissions that are potentially dangerous. The script tests all folders in $pathsToCheck and reports any...
Get IP Address Geolocation
Would you like to know where a public IP address is located? Provided you have Internet access, you can query one of the public information...
Get Current IP Address
Here is a quick way to get all IP addresses assigned to your computer: #requires -Version 1 $ipaddress = [System.Net.DNS]::GetHostByName($null)...
Validating Domain Credentials
To check credentials (username plus password) against your current domain, you can use this approach: #requires -Version 1 $username =...
Safely Use UNC Paths
Whenever you use UNC paths in PowerShell, your script may break. Since a UNC path has no drive letter, PowerShell looks at the current directory...
Using Splatting
With splatting, you can call cmdlets and programmatically control the parameters you submit. To do this, add the parameters and values to a hash...
Reading RSS Feeds
RSS feeds can be read by using an XML object, however XML objects do not support proxies. Here is an example that uses Invoke-WebRequest to retrieve...
Getting Registry Values and Value Types
Get-ItemProperty can easily read registry values, but you do not get back any information about the registry value type. Get-ItemProperty -Path...
Finding Information about TV Series
PowerShell can query websites that deliver XML content, and here is an example on how to query a movie database. Simply adjust the name of the TV...
Comparing Folder Content
To quickly compare folder content and find out files that exist only in one of two folders, try this example: $list1 = Get-ChildItem...
Encoded Passwords
If you must put a credential object in your script, here is a way how you can convert a secure string into encrypted text: $password = Read-Host...
Find All Active Drive Letters
To quickly get a list of all drive letters in use, try this: #requires -Version 1 [Environment]::GetLogicalDrives() The result is a list of all...
Encrypting Text Information Using Passphrase
PowerShell 3.0 and later In a previous tip we explained how you can use the Windows product ID stored in the Windows Registry to encrypt some text...
Encrypting Information with Windows ProductID
PowerShell 3.0 and later To store secret information, you can use a SecureString object and save it to disk. PowerShell automatically takes the user...
Finding Exchange Mailboxes
Microsoft Exchange 2013 To find the number of mailboxes, simply use the Exchange cmdlets and have Measure-Object count the results: Get-Mailbox...
Clever Parameter Validation
PowerShell 2.0 and later When you create PowerShell functions with parameters, make sure you tell PowerShell what kind of values the parameter...
Discovering High Impact Cmdlets
All Versions Cmdlets can declare how severe their impact is. Typically, cmdlets that make changes to the system that cannot be undone will have an...
ISE Auto-Completion Trick
PowerShell 3.0 ISE and later When you want to select the information returned by a cmdlet, you typically use Select-Object: Get-Process |...