powertips

Analyzing System Restarts

To find out when a system restarted and why, use the below code to extract the relevant information from the System event log: Get-EventLog -LogName...

Sending Emails Securely (via SSL)

In a previous tip we showed how to use the Send-MailMessage cmdlet to send off emails and preserve special characters by using UTF8 encoding. When...

Sending Emails with Special Characters

PowerShell has built-in support for sending emails: Send-MailMessage! All you need is an SMTP server. However, with standard encoding you may run...

Check Active Internet Connection

If your machine is connected to the Internet more than once, let's say cabled and wireless at the same time, which connection is used?...

Use WMI and WQL!

WMI is a great information resource, and Get-WmiObject makes it easy to retrieve WMI instances. First, use -List parameter to find WMI class names....

Convert to Numeric

Whenever PowerShell asks for user input or reads text file content, the results are text strings. If you expect numbers and want to calculate, make...

Read/Delete/Move Every X. File

Occasionally, you may want to act on every 2nd or 3rd file in a folder (or line in a file). The easiest way to identify every x. element is to use...

Managing Internet Cookies

Ever wondered what Internet sites store inside cookies when you visit them? This line will dump all cookies: PS> dir...

Create Own Driver Tool

Thanks to Peter Bishop, here's an enhancement to one of our earlier tips. It turns the command line output delivered by driverquery.exe into a...

Ignoring Empty Lines

To read in a text file and skip blank lines, try this: $file = 'c:\sometextfile.txt' Get-Content $file | Where-Object { $_.Trim() -ne...

Creating System Footprints

WMI can retrieve a lot more object instances than you might think. If you submit a parent class, Get-WmiObject returns all instances of all derived...

Retrieve Exchange Rates

If you need up-to-date exchange rates, try loading the rates via XML from the European Central Bank. This sample gets you the latest exchange rates...

Bulk-Creating PDF Files from Word

To convert a whole folder full of MS Word documents to PDF, here's a function that might help:/p> function Export-WordToPDF { param(...

Reading the Clipboard

What if you wanted to paste information from the clipboard? No sweat, here is a Get-Clipboard function that outputs any text held by the clipboard:...

Sending Text to Clipboard Everywhere

In a previous tip you learned how to use clip.exe to send results to the clipboard. But what if you don't have clip.exe (let's say on...

Sending Text to the Clipboard

Wouldn't it be fun if you could send results directly to the clipboard? Well, beginning with Windows Vista you can - thanks to clip.exe: PS>...

Spying on Parameters

Your own PowerShell functions can have the same sophisticated parameters, parameter types and parameter sets that you know from cmdlets. However, it...

Removing Shares (Remotely, Too)

In a previous tip you learned how you can create ad-hoc shares using WMI. These shares persist until you remove them again. So if you'd like to...

Creating Shares Remotely

Let's assume you need to access another machine's file system but there is no network share available. Provided you have local administrator...

Opening MsgBoxes

Need a quick message box to display something or ask a question? Fortunately, PowerShell can access old COM components. Here's a line that...

Creating a "Better" More

In a previous tip you learned that using "more" to paginate output can be dangerous, and instead you should use Out-Host -Paging. To...

Creating Your Own Get-Driver Tool

Some code snippets are really valuable, so you should turn them into functions to keep around as new PowerShell commands. Here's a sample...

Finding More Driver Information

In a previous tip you learned how you can convert raw CSV data from a console application such as driverquery.exe into real PS objects. Let's...

Finding Driver Information

driverquery.exe returns all kinds of information about installed drivers, but the information seems a bit useless at first: PS> driverquery.exe...

Finding Standard Parameter Names

In a previous tip, we suggested you to use standard parameter names for your own functions. To get a feeling for what the parameter names are that...

Best Practice for PowerShell Functions

This is a best-practice message: when you create your own function, here are some things you should consider: - Function name: use cmdlet naming...

1 69 70 71 72 73 98