When you compare version strings, PowerShell will use alphanumeric algorithms, which may lead to confusing results: '3.4.22.12' -gt...
powertips
Categories
- Free tools
- SQL Admin Toolset
- SQL Compliance Manager
- SQL Defrag Manager
- SQL Diagnostic Manager for MySQL
- SQL Diagnostic Manager for SQL Server
- SQL Diagnostic Manager Pro
- SQL Doctor
- SQL Enterprise Job Manager
- SQL Inventory Manager
- SQL Query Tuner for SQL Server
- SQL Safe Backup
- SQL Secure
- SQL Workload Analysis for SQL Server
- Uptime Infrastructure Monitor Formerly Uptime
View Object Inheritance
A hidden object property called "PSTypeNames" will tell you the object type as well as the inherited chain: (Get-WMIObject...
Using Scripts to Validate Input
For tricky validation checks, you should use arbitrary PowerShell code to validate. The function Copy-OldFiles will only accept files (no folders)...
Restrict Input to Numeric Ranges
Let's say you'd like to set the PowerShell console cursor size. This size must be a number between 0 and 100. The following template will...
Converting Object Types
Once you know the name of an object type, you can use that type for conversion. The next line converts a string into a date-time type: [DateTime]...
Finding Object Types with Powershell
Anything in PowerShell is an object. You can use GetType() to get the object type:...
Validate Input Using Regular Expressions
Function parameters can be validated using standard regular expressions. For example, the next template function accepts only valid Knowledge Base...
Limiting String Input Length
If a function parameter should receive a string of a given length only, you should use the following validation attribute. In the example, it limits...
Limiting Number of Arguments
Function parameters can receive multiple values when they accept arrays. You should use this template to limit the number of values acceptable:...
Defining Alias Properties
Your functions can have properties with built-in alias names. The user can then either use the descriptive "long" name or its short and...
Validate Set of Inputs
If you need to limit a function parameter to only a set of allowed choices, you should use the next example: function Get-24hEventLogEntries...
Finding Cmdlets With a Given Parameter
Finding cmdlets by name is easy: Get-Command *service* -commandType Cmdlet But how can you list all cmdlets that support a given parameter? If...
Removing All Internet Explorer Cookies
You'd probably like to regularly clean your machine and remove all cookies set by Web sites you may have visited? Here is how: Dir...
Listing Internet Explorer Cookies
Have you ever wanted to find out who stored your information while you were surfing the Web? Check out your cookies folder: Dir...
Remove Recents Folder
Windows uses the special recents folder to remember which files you have opened. You can have a look to check what Windows has stored: Dir...
Bulk-Changing File Extensions
Changing file extensions can be a quick one-line operation. The next line renames all ps1 PowerShell script files found in your user profile and...
Displaying Hex Dumps
PowerShell can read plain text, but it can also read binary content. Here is a little function that creates a "hex dump" of any binary...
Reading File "Magic Number"
File types are not entirely dependent on file extension. Rather, binary files have internal ID numbers called "magic numbers" that tell...
Working with Path Names
The .NET System.IO.Path class has a number of very useful static methods that you can use to extract file extensions. Here is how you can get a list...
Finding A Users Desktop Folder
The .NET Environment class can provide the paths to common folders like a user desktop: Environment]::GetFolderPath("Desktop") Use this...
Writing Your Own Event Log Entries
If you have registered a new event log source, such as "PowerShellScripts" as described in the previous tip, you can now write your own...
Adding New Event Log Sources
Every event log maintains a list of registered sources. You need a source name if you want to write your own event log entries. Make sure you have...
Lowering Process Priority
Sometimes, you may want to lower process priority for some processes. That's a PowerShell one liner. Note that the next line lowers priority for...
Getting Help on WMI Methods
Have you ever wanted to get a list of all WMI methods present inside a specific WMI class – plus a meaningful description and a list of all...
Renewing all DHCP Leases
Some WMI classes contain static methods. Static methods do not require an instance....
Calling ChkDsk via WMI
Some WMI classes contain methods that you can call to invoke some action. For example, the next line initiates a disk check on drive D:...
Getting Help for WMI Classes
In a previous tip, you discovered how to search for WMI classes like Win32_VideoController. Now, what exactly is the purpose of this class? You can...
Finding Interesting WMI Classes
WMI is a huge repository. If you want to get to useful information, you will need to specify the name of a valid WMI class. Fortunately, it is easy...
Rename Drive Label
WMI can also read any drive label (the name that appears next to a drive inside Explorer), and you can change the drive label, too—provided...
Remove Empty Entries
One little known fact is that Where-Object is a cool and simple way of removing empty objects. Let's say you want to list all network adapters...