In a previous tip we showed that Trim() is an unsafe way for removing file extensions. A safe way uses .NET methods:...
database-tools
Removing File Extensions (Unsafe)
Some users use Trim() to remove file extensions like this: 'c:\test\file.txt'.Trim('.txt') c:\test\file This seems to work great,...
Finding Useful WMI Classes
To find the most useful WMI classes you can use Get-WmiObject, and let PowerShell provide you with a hand-picked list: Select-XML...
Finding Type Definitions
PowerShell enhances many .NET types and adds additional information. These changes are defined in xml files. To list all .NET types that get...
Analyze Cmdlet Results
There are two great ways to analyze the results a cmdlet returns: you can send the results to Get-Member to get a formal analysis, telling you the...
Listing Process Owners
In a previous tip, you learned that there is a hidden host process named wsmprovhost.exe whenever someone else visits your computer using PowerShell...
Detecting Remote Visitors
Whenever someone connects to your computer using PowerShell remoting, there is a host process called wsmprovhost.exe. You can only see processes...
Echoing The Error Channel
To control which output from a batch file is considered "a result" and which output should rather always be visible to the user, you can...
Active Directory In Up.time 5.5.0
I am trying to get AD authentication working in up.time 5.5.0 as I have several engineers in different locations that want to evaluate it. But so...
Make Sure Folder Exists
To ensure that a given folder exists, you can stick to trial-and-error, and hide error messages: New-Item c:\somefolder\anotherfolder\yetanother...
List NTFS Permissions
To view NTFS permissions for folders or files, use Get-Acl. It won't show you the actual permissions at first, but you can make them visible...
Duplicate Output
Sometimes, you may want to store command results in a variable and at the same time, output it to the console. Once you assign results to a...
Multiple Text Replace (Fast)
In a previous tip, we showed you how to replace multiple different characters in a text using the Switch statement. While this works well, it is not...
Speed Up Loops
First, compare these two code samples: $array = 1..10000 Measure-Command { for ($x=0
Set Clipboard
If you are using Windows Vista or better, you can pipe text to clip.exe to copy it to your clipboard: Dir $env:windir | clip Here is...
Get-Clipboard
If your PowerShell host uses the STA mode, you can easily read clipboard content like this: function Get-Clipboard { if...
Test for STA mode
By default, the PowerShell console does not use the STA mode whereas the ISE editor does. STA is needed to run Windows Presentation Foundation...
Multiple Text Replace
Imagine that you need to replace a number of different characters in a text. For example, you need to remove special characters or escape something....
Switch Accepts Arrays
Did you know that the Switch statement can accept arrays? Use this sample to translate numbers into words: PS> switch ( 1,5,2,4,3,1 ) { 1 {...
Check For Numeric Characters
Try this if you need to check a single character and find out whether or not it is numeric: PS > [char]::IsNumber('1') True PS >...
Check Array Content With Wildcards
You may know the -contains operator. Try using it to check whether an array contains a specific element: PS > $names = dir $env:windir |...
Adding New PowerShell Drives
You can add a bunch of interesting new drives to PowerShell with just a single line of code:...
Re-Assigning Types to Variables
You can no longer assign other types when you strongly type a variable: [Int]$a = 1 $a = 'does not work' However, you can always...
Generate Random Passwords
In a previous tip, we showed you how to create random passwords. Thanks to your feedback, here is an even shorter version: -join...