database-tools

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

Persisting Comparison Snapshots

Whenever you'd like to compare long-time results or compare data on different machines, you want to use persisted result sets. Persisted result...

Monthly Capacity Reporting

Monthly Capacity Reporting I need to provide server by server (Wintel) some preety management pictures that show CPU both peaks and average with a...

Finding Folder Changes

Compare-Object can help you monitor folder content and find changes. To monitor, first create an initial snapshot. At a later time, you can then...

Comparing Results

PowerShell makes it easy to compare results and find only things that changed. For example, you may want to list only processes that started after a...

Setting Properties on AD Users

If you'd like to find Users in your Active Directory and bulk-change certain properties, you may not need 3rd party extensions. Here is an...

Calculating Space Consumption

If you ever wanted to find out which folder in your profile consumes the most space (or want to check user profiles to make sure people do not...

Write-Protected Arrays

Arrays are by default read/write so you cannot lock down arrays and make them read-only. To create a read-only array, you can "upgrade" it...

Turbo-Charging Arrays

Simple arrays have no built-in mechanism to insert new elements or extract elements at given positions. For example, to extract the 5. element from...

Creating Numeric Ranges

There is a clever trick in PowerShell to create numeric ranges that you probably know: 1..10 But did you know you can use variables with this trick?...

Creating Random Numbers

Ever wanted to create an electronic dice (or needed random numbers for other purposes)? With PowerShell, simply instantiate a Random object and call...

Creating Lists of Letters

The easiest way to create an array of letters is to convert an array of numbers into an array of characters like this: $letters = [char[]](97..122)

Sorting Arrays

Let's assume you have an array of items which you would like to sort. Here is the PowerShell way: $array = 1,5,32,5,7$array | Sort-Object$array...

Analyzing URLs

URLs contain a lot of information which can be automatically parsed by PowerShell. Simply convert a URL to the System.URI type. Once you did this,...

Escaping Text Strings

HTML on web pages uses tags and other special characters to define the page. To make sure text is not misinterpreted as HTML tags, you may want to...

Checking Host Name Type

To check whether a string contains a valid host name, you can use the CheckHostName() method provided by the System.URI type. It will return...

Validating a URL

To make sure user input is a valid URL, you can use the System.URI type. Try to convert the raw string into this type. If it works, the string is a...

Reversing Array Order

To reverse the order of elements in an array, the most efficient way is to use the [Array] type and its static method Reverse(): # Create an array...