Powershell | I do stuff sometimes. | Page 2

Ramblings about things.

Archives

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

Powershell Unrar script v2.0!


This one is a little more andvanced, as it “cleans up” after itself by deleting the .rar parent folder after successfully extracting it. Of course, use this at your own risk. It tends to be a little ruthless, considering there’s no going back as soon as the parent folder is deleted. In other news: IT’S…

Read More

List Windows Server OS


I always forget the correct line for listing these things with WMI. Therefore, it’s now perpetuated on Fuffle.net. =) cls $servers = get-content “C:tempserverlist.txt” foreach ($s in $servers){ $gwmi = (Get-WmiObject -ComputerName $s -class win32_operatingsystem -ErrorAction SilentlyContinue).caption write-host “$s – IP:”([System.Net.Dns]::GetHostAddresses($s)) – $gwmi -foregroundcolor “green”} -F

Read More

Powershell Ping


This neat little thing wil test connection for a list of pingable DNS names (URLS, switches, servers, computers, whatever), and output the result in a list with the objects IP address(es). If the ICMP ping does not reach the object, it outputs this and jumps to the next object on its list. Hurray! cls $servers…

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

Find server OS with Powershell and TTL


This handy little thing will identify the Operating System on one or more servers, using the OS’s default TTL value as a trigger. (Some OS’ uses different TTL values. Most of them are listed on this site.) cls $servers = “Server1″,”Server2” foreach ($server in $servers) { $TTL = Test-Connection $server -Count 1 | select -exp…

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

← OLDER POSTS NEWER POSTS →

  • Archives