Category: Powershell

  • 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 03 – overwrites existing contents…

  • 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 to use the -ExcludeProperty switch…

  • 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, startmode, state, status if (($_.name…

  • Using Powershell to report on disk space

    I have several Windows servers serving as our Oracle front end servers, unfortunately, these servers have limited disk space on their OS and Data drives. Each morning these need to be checked to ensure that the drives don’t fill which result in problems. So, to save logging on to each server each morning I investigated…