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

SCCM Lab: Part 2 – DHCP and DNS Server roles on our AD controller


This part in the SCCM Lab series will cover installing and configuring the DHCP and DNS Server roles on our headless Windows 2019 server we configured in Part 1. Here we go. The DNS server was created when AD DS role installed the root forest. We can see that the DNS role is installed using the Get-WindowsFeature command:…

Read More

SCCM Lab: Part 1 – AD Controller


I am currently setting up a new SCCM testenvironment in my home-lab – this will be one of (possibly) many quick-n-dirty how-to’s for setting up a functioning SCCM lab. First things first – the lab wil consist of Server 2019 and Windows 10 servers and clients. The SCCM version used is SCCM current-branch 1902. All…

Read More

Powershell: Test connection on computer port


I use this if telnet is not layin’ around – mainly to test if a computer is reachable on a specific TCPport. try { $portquery = New-Object System.Net.Sockets.TcpClient(“SERVERNAME”, PORTNUMBER) $portquery.Close() return $true } catch [system.exception] { return $false } F

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

Powershell: Convert string to date


The string: $datestring = “27. januar 2016 04:20:17” Convert this to date: $date = [datetime]::ParseExact(“$datestring”,”dd.MM.yyyy hh:mm:ss”,$null) – F

Read More

SCOM: Get Subscriber in Subscription


This little thing will search through, and get all subscribers containing your searchword in any subscription you may have set up in SCOM. param( [String]$searchword ) $sub = Get-SCOMNotificationSubscription | select displayname,torecipients write-host “Searchword: “”$searchword”” exists in the following subscriptions:” foreach ($s in $sub){ $recipient = $s.torecipients.name if ($recipient -like “$searchword”){ write-host “”$s.displayname”” } }…

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

Request Template Certificates using CertReq and Powershell


Installing SCOM agents on non-domain servers can be a real time-consuming affair, especially the Create template-request-export-import-certificates procedure. I decided to use my basic certificate and CertReq knowlegde to create this little script that helps me automate the whole thing. NOTE: This is meant for inspiration only. If will for the most part not work in…

Read More

Get MSMQ (Message Queuing) queues with Powershell


Simple, yet effective. Especially if you don’t have the MSMQ module for PS. $queues = Get-WmiObject -computername “YourServer” Win32_PerfFormattedData_msmq_MSMQQueue $queues | ft -AutoSize -property Name,MessagesInQueue – F

Read More

← OLDER POSTS

  • Archives