Powershell

Check for a Battery

If your script needs to know whether your computer has a battery, you can ask WMI. Here is a small function: function Has-Battery {@(Get-WmiObject...

read more

Creating Your own Types

Did you know that you can compile any .NET source code on the fly and use this to create your own types? Here is an example illustrating how to...

read more

Calculating Server Uptime

Have you ever wanted to find out the effective uptime of your PC (or some servers)? The information can be found inside the event log. Here is an...

read more

Getting Installed Updates

PowerShell is great for parsing log files. Here is a function that extracts all installed Windows updates from an internal log file and returns the...

read more

Replace Text in Files

Often, some text will need to be replaced in a text file. That's easy with Get-Content and Set-Content - or not? Get-Content c:somefile.txt |...

read more

Adding Extra Information

Sometimes you may want to tag results returned by a cmdlet with some extra information, such as a reference to some PC name or a timestamp. You can...

read more

Making Objects Read/Write

Whenever you pipe objects through Select-Object, you actually get a copy of the original object. All properties are now readable and writeable, so...

read more

Creating Relative Dates

To create relative dates like "10 days ago," there are two paths. Administrators often add or remove time spans created by New-Timespan:...

read more

Create Remoting Solutions

Whenever you use WMI (Get-WMIObject) to retrieve information, it's a snap to turn a local solution into a remotable solution. You can just add...

read more

How Much RAM Do You Have?

Ever wondered what type of RAM your PC uses and if there is a bank available to add more? Ask WMI! This example also converts the cryptic type codes...

read more

Removing Empty Things

How do you exclude objects based on empty properties? For example, WMI returns all kinds of "network adapters:" Get-WMIObject...

read more

Filtering Day of Week

You can also use this little helper function if you run scripts every day and want to make sure they don't do anything on weekends: function...

read more