database-tools

Stripping Decimals Without Rounding

When you divide numbers and just want the decimals before the decimal point, you could cast the result to integer. However, this would also round...

The Two Faces of -match

The -match operator can be extremely useful because it accepts regular expression patterns and extracts the information that matches the pattern:...

Finding Email of Logged On User

In an Active Directory environment, PowerShell can easily find the currently logged on user and retrieve AD information about that user, for...

Remotely Launching Processes

Unfortunately, the Start-Process cmdlet has no -ComputerName parameter so you cannot use it to launch processes on remote machines. Use WMI instead!...

Keeping Remote Programs Running

When you use PowerShell Remoting (like the Enter-PSSession cmdlet) to connect to another machine and then start a program using Start-Process, the...

Converting TABs to Spaces

When you want to publish PowerShell code, you may want to make sure that all TAB characters are converted to one or more spaces to save space....

Log security and log tables.

Accidentially I came across the statement "SHOW GRANTS requires the SELECT privilege for the mysql database." in MySQL  documentation...

Removing Multiple White Spaces

Removing multiple white spaces from text is easy in PowerShell. Simply use -replace operator and look for whitespaces ("\s") that occur...

Using Shared Variables

By default, all variables created in functions are local, so they only exist within that function and all functions that are called from within this...

Catching Errors

In forums, people often get confused with error handling. For example, this code does not call the error handler. Instead, the red PowerShell error...

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...