Write to a text file using Powershell

While looking for a method to generate some logging in a Powershell script to aid debugging I came across several suggestions… #Method 01 – appends contents $LogFile =”C:\PsTools\Method01.log” $DateTime = Get-Date Write-Output $DateTime “Performing some operation” | Add-Content $LogFile #Method 02 – appends contents Add-Content “C:\PsTools\Method02.log” “Performing some operation” #Method Continue Reading

Excluding WMI system properties with Powershell

When using Windows Management Instrumentation (WMI)  in your Powershell script you will see a load of system properties returned. These are indicated by a preceding “__” (double underscore) as seen below when issuing get-wmiobject -class “Win32_Processor”:   An obvious attempt to prevent these system properties from being returned would be Continue Reading

Checking services with Powershell

I use this script to check the Oracle services on the list of servers contained in servers.txt. The results are output to ServiceResults.html file. Listing for checkServices.ps1 process{ $servername = $_ $serviceArray = Get-WmiObject -class Win32_Service -computerName $servername $temp = @() $serviceArray foreach { $serviceinfo = “” select servername, name, Continue Reading