Powershell | I do stuff sometimes.

Ramblings about things.

Archives

Powershell: Create Event with parameters


This function will let you stamp events to the Windows EventLog, and feed the event with filterable parameterdata (which in the cases you use SCOM to sniff events, is pretty awesome). I use this all the time in cases where a script should dump some kind of result to the eventlog, and using SCOM to…

Read More

Powershell: Get file- and foldersize for given path


Quick and dirty little thing I use to get the file- and foldersize for any given path. # Get-pathsize.ps1 # Use: C:scriptsget-pathsize.ps1 -path <your-path> param ( $path ) try { Get-ChildItem $path -Hidden -ErrorAction Stop } catch { $_.exception break } $colItems = (Get-ChildItem $path -recurse | Measure-Object -property length -sum) [int]$size = [math]::round($colItems.sum /1MB,…

Read More

SCOM: Command Channel Script


This little script is what I use in cooperation with the SCOM Command Channel to parse and send SCOM alerts to a logfile. The script will take the SCOM alert parameters and put them neatly in a .log file, one file for each alert I want. This, of course, is customizable – I just like…

Read More

Query MSSQL with Powershell


I often use different variety of this snippet to do stuff with MSSQL databases (and other types as well, with minor changes to the script). The script will use SQL Auth by default. To change this to Windows Auth, change the Connection String to: $SqlConnection.ConnectionString = “Server = $SQLServer; Database = $SQLDBname; Integrated Security =…

Read More

Test webservices with Powershell


I use this little thing to test webservices (by invoking SOAP/GET request etc) whenever I want to parse the output to, say, Windows Event Logs, or the nearest SoapUI installation is far far away. The $request.SetRequestHeader parameters may vary from situation to situation, but in most cases this code should be sufficient for simple Webservices….

Read More

Output displayname and IP address for SCOMagents


Got bored – wrote this little thing to output FQDN and IPaddress for all Windows and UnixLinux agents in my lab environment. Could be useful for some people maybe.   ipmo operationsmanager $nixservers = get-scomclass -name “Microsoft.Unix.Computer” | Get-SCOMMonitoringObject $winservers = Get-SCOMClass -name “Microsoft.Windows.Computer” | Get-SCOMMonitoringObject Write-host “—————————————————————–” write-host “——————– Unix Computers and IPs ———————“…

Read More

Monitor Active/Passive Clustered Services… in SCOM?


I was playing around in Powershell the other day, and made this little thingy to help me monitor clustered Windows Services in an Active/Passive Windows Cluster solution. The script checks if specific Windows Services are running or not, and determines which node is active in the cluster by using the get-wmiobject cmdlet. There are many…

Read More

SCOM: Alert Task – Copy alert to clipboard


In our daily line of work, we sometimes need to show server admins and system managers alerts related to their infrastructure. Have you ever tried to copy/paste the Alert Details for an alert? It looks like crap, and contains alot of information the server admins and system managers couldn’t care less about. To make this…

Read More

Unrar archives with Powershell


Are you like me and have literally thousands of .rar archived material laying around on old disks? It can be a pain in the lower region of the backside of your body to unrar all of those files without it being time consuming and boring as hell. After some fiddlin’ around in PowerShell and some…

Read More

Powershell Execution Policy


The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies: Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode. AllSigned – Only scripts signed by a trusted publisher can be run. RemoteSigned – Downloaded scripts…

Read More

← OLDER POSTS

  • Archives