In a previous tip we talked about using PowerShell Remoting to execute code on a remote machine, and how to use "using:" to carry over...
database-tools
Using RegEx to Filter Files
Get-ChildItem supports basic wildcards, but it does not support the rich feature set of regular expressions. If you combine Get-ChildItem with...
Enable PowerShell Remoting in Two Lines of Code
One common problem with enabling PowerShell Remoting on your box is public networks. As long as there are active network connection labeled as...
Using "Using:" On Remote PowerShell Sessions
When you use PowerShell Remoting to execute scripts and commands on another machine, you may have run into an issue like this: $class =...
Replacing Variable Names in ISE 3.0 Editor
If you want to replace variables in a PowerShell script, in PowerShell ISE 3.0 you can use the following function: function Replace-Variable {...
Quick Reference Sheets for PowerShell
PowershellMagazine.com has prepared a set of very useful quick reference sheets for PowerShell 3.0, the ISE editor and more. Microsoft now offers...
Controlling Admin PowerShell from Non-Elevated PowerShell
In a previous tip we illustrated how you can use Start-Process to launch an elevated PowerShell from within your script to do elevated tasks. The...
Reversing GUIDs
Active Directory and other services sometimes use a custom GUID format. To convert a GUID to that format, all blocks of the GUID need to be...
Preventing Direct Function Calls
If you must make sure that a function within your script is inaccessible from outside calls, you can use this trick. Save this code as a script...
Use Select-String For Fast Textfile Parsing
Select-String is an extremely useful cmdlet for parsing log files. You can use it to dump all lines in a text file that contain a certain keyword....
Replace Escape
There are two ways for replacing text, and both have their advantages and pitfalls: Each string has a Replace() method which works very...
Changing Scheduled Tasks with PowerShell
PowerShell can read and also change any part of a scheduled task. Just make sure you have appropriate permissions and run PowerShell elevated....
PowerShell 3.0 Help Available on Non-US-Systems
PowerShell 3.0 does not ship with help files. Instead, they need to be downloaded separately using Update-Help. Unfortunately, PowerShell 3.0 help...
Examining Scheduled Tasks
There is a COM interface that you can use to select and dump any scheduled task definition. Just make sure you are running PowerShell with full...
Reversing Text Strings
Here's a simple trick to reverse a text string: $text = 'Hello World' $text = $Text.ToCharArray() [Array]::Reverse($text) -join $text...
Running Portions of Code Elevated
Let's assume your script may or may not need to do a privileged operation, for example write a value to a HKEY_LOCAL_MACHINE branch, depending...
Creating New Objects – Alternative
There are many ways in PowerShell to create new objects. One of the more advanced approaches uses a hash table to determine object properties and...
Counting Number of Files – Fast!
If you need to know the number of files in a folder, there are different approaches with different advantages and disadvantages. The first one is...
Don't See Alert Under My Portal My Alert
I have problem with the alert in my portal. One user don’t see anything in Myportal but it’s setup like all the other any idea? What...
Turning CSV-Files into "Databases"
Let's assume you have a CSV file with information that you need to frequently look up. For example, the CSV file may contain server names and...
Testing Event Log Names and Sources
Write-EventLog lets you write custom entries to event logs, and New-EventLog can add new event logs and event sources. Which raises the question:...
Writing Text Information Fast
If you want to write plain text information to a file, don't use Out-File. Instead, use Set-Content. It is much faster: $tempfile1 =...
Quickly Replace Words in Text File
In a previous tip we explained how you can convert a string array into one big string. That's a prerequisite for quickly searching and replacing...
Converting String Array in String
When you use Get-Content to read the content of a text file, you always get back a string array. So each line of your text file is kept separately....