powertips

Encrypting PowerShell Scripts

Sometimes, you may want to hide the code of your PowerShell script in order to protect passwords contained within the code. One way to safely...

Finding Out Whether A Web Page Is Open

The Shell.Application COM object returns a list of all open windows, including all opened IE browser windows. This way, you can find out whether a...

Accessing Internet Explorer

Accessing Internet Explorer can be useful for obtaining Web content. The usual approach uses a COM object called InternetExplorer.Application like...

Detect DHCP State

You can use WMI and Win32_NetworkAdapterConfiguration to determine whether a computer uses DHCP to acquire an IP address. Simply look for all...

Select Folder-Dialog

Want to provide your users with a neat dialog to select folders? Simply use a COM object called Shell.Application, which provides the...

Sending Simple SMTP Mail

You need to notify an admin that something happened or something is finished and would like to send a quick e-mail from inside your PowerShell...

Check Online Status

When managing more than just one system, you may want to remotely access those systems. Maybe you use WMI to do that. However, when you try and...

An Easy InputBox

All user input and output normally occurs inside the PowerShell console. Simply access the .NET framework directly if you'd like to get back the...

Finding Current Script Path

Ever wanted to locate the path of your current PowerShell script? This can be useful to call other scripts or resources in the same folder. To...

Finding Aliases for a Command

PowerShell defines a lot of shortcuts (aliases) for most commands. You may want to determine whether there is a shortcut if you find yourself using...

Clone NTFS Permissions

NTFS access permissions can be complex and tricky. To quickly assign NTFS permissions to a new folder, you can simply clone permissions from another...

Finding and Deleting Orphaned Shares

Maybe you never noticed but when you delete folders that were shared on the network, the share may be left behind. To locate shares that have no...

Creating HTML Reports

PowerShell can convert objects into HTML using ConvertTo-HTML. By adding a bit of custom formatting, your reports can be colorful and cool. The...

Creating A Computer Profile

Often, information needed to comprehensively profile a computer comes from a number of sources. A great way to meld these different bits of...

Shutting Down Computers Remotely

WMI not only provides rich information, it also supplies methods that you can call to take action. In the next example, you can forcefully shut down...

Finding Out Interesting WMI Classes

WMI provides a wealth of information as long as you know the name of the WMI class that represents the entity you are seeking. Fortunately,...

Accessing Servers Remotely via WMI

WMI is a fantastic source of information! Best of all, it works locally as well as remotely. For example, the next line gives you details about your...

Filtering Events by Date and Time

As you have discovered in a previous tip, reading Eventlog entries is fairly simple using WMI and Win32_NTLogEvent: Get-WmiObject Win32_NTLogEvent...

Analyzing Event Logs

Event logs are a great source of information. The only problem is that they tend to be overwhelming. Try using WMI and the Win32_NTLogEvent class to...

Reading Text Files

Reading text files is easy using the Get-Content cmdlet: $text = Get-Content $env:windirwindowsupdate.log However, Get-Content reads the file line...

Converting ASCII and Characters

To convert the ASCII value to a character, use type casting like this: [char]65 To do the opposite and convert a character to its ascii value, use...

Checking File and Folder Permissions

Get-Acl is a convenient Cmdlet to expose NTFS file and folder settings. For example, to get a list of ownerships for a folder content, do this: Dir...

Sorting Text Files

You need to sort a text file, maybe a list of servers or names? Here is how: $file = $homeserverlist.txtGet-Content $file | Sort-Object |...

Playing a Song with Media Player

Windows Media Player can be accessed using COM, and WMP in turn gives you access to your entire media. Using GetByName(), you can directly access...

Listing Your Media Collection

Windows Media Player (WMP) gives you access to all of your media stored on your computer. PowerShell can access this information through COM using...

Cleaning Document Folders

Often, in your document folders a lot of files exist, and most of the time they are not really organized. With the help of a little PowerShell...