Skip to content

Instantly share code, notes, and snippets.

View stegenfeldt's full-sized avatar

Samuel Tegenfeldt stegenfeldt

View GitHub Profile
@stegenfeldt
stegenfeldt / Export-SCOMMPInventory.ps1
Last active February 15, 2024 14:20
Export a JSON file of SCOM Management Packs and Computers Using Them
<#
Script will generate a json file listing management packs and
the servers (computers) with instances from that management pack
ex.
{
"Management.Pack.Name.1": [
"server1.principal.name",
...
"server2.principal.name"
@stegenfeldt
stegenfeldt / Get-CoffeeRatio.ps1
Created April 30, 2021 12:32
Simple powershell function to calculate coffee ratio
function Get-CoffeeRatio {
param([float]$g, [float]$ml)
for($i = $g; $i -gt 1;$i--) {
$mlmod = $ml % $i
$gmod = $g % $i
if ($mlmod -eq 0 -and $gmod -eq 0) {
$g = $g / $i
$ml = $ml / $i
break
@stegenfeldt
stegenfeldt / Update-SCOMAgentDistribution.ps1
Last active November 25, 2020 15:18
Redistribute SCOM Agents Evenly between Management Servers/Gateways
Set-PSDebug -Strict
function Get-SCOMFailoverResourcePools
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
@stegenfeldt
stegenfeldt / Get-LatestMSSQLVersions.ps1
Created July 2, 2020 13:06
Get-LatestMSSQLVersions.ps1
function Get-SQLCUKBProductVersion ($url) {
$wr = Invoke-WebRequest -UseBasicParsing -Uri $url
$wrContent = $wr.RawContent
$matchFound = $wrContent -match "<table.*?>(.*)</table>?" #extracting tables
## This is the table we're looking for
# <table class="table ng-scope">
# <tbody>
# <tr>
@stegenfeldt
stegenfeldt / README.md
Created May 20, 2019 12:24
Fast Powershell Async Ping

Test-AsyncPing.ps1

The script is made as a proof-of-concept to make speedy asynchronos ping over a range (array) of IP-addresses.
It is made for speed over quality, use-case is frequent monitoring checks where a gap or two is OK,
and only pings each IP in the array once.

@stegenfeldt
stegenfeldt / TGAsyncPing.ps1m
Created January 30, 2019 08:35
Fast Async Ping Module
<#
.Synopsis
Executes a single AsyncPing on each Address in -AddressList
.DESCRIPTION
Takes a list (array) of addresses, IP or DNS-Names, and performs a single AsyncPing against the target.
This CmdLet is made to do quick and dirty fast pings against a larger number of targets.
.EXAMPLE
# Ping www.teknoglot.se and www.google.se, 5s timeout
Test-AsyncPing -AddressList "www.teknoglot.se","www.google.se" -Timeout 5000
.EXAMPLE
@stegenfeldt
stegenfeldt / Disable-SCOMMPMonitoring.ps1
Created April 27, 2018 11:39
Disable-SCOMMPMonitoring.ps1 - Create overrides in bulk on all enabled monitors/rules in MP
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string] $MPPrefix
,[Parameter(Mandatory=$true)]
[string] $MPSearchString
,[Parameter(Mandatory=$true)]
[string] $ManagementPackDisplayName
)
@stegenfeldt
stegenfeldt / Set-cSCOMNonRepeatedRuleAlertsToClosed.ps1
Created April 17, 2018 07:18
Close SCOM Rule Alerts with no Repeats
import-module -name operationsmanager
New-SCOMManagementGroupConnection
$alerts = Get-SCOMAlert -ResolutionState 0 | ?{($_.IsMonitorAlert -eq $false) -and ($_.RepeatCount -eq 0)}
Set-SCOMAlert -Alert $alerts -ResolutionState 255
@stegenfeldt
stegenfeldt / FindOMDBOrphanedServers.sql
Created April 10, 2018 08:00
OMDB SQL Query - Finding Orphaned Server objects.
-- This Script will find probable orphaned servers in the
-- OMDB BaseManagedEntity database.
-- Replace 'PREFIX[0-9]%.domain.fqdn' with whatever pattern matching that suits your naming standard.
-- A server with only an agent will still have more than one row,
-- same goes for cluster names/virtual names.
with
ServerRowCount as (
select
@stegenfeldt
stegenfeldt / Update-SCOMAIXCertificate.ps1
Last active June 29, 2017 14:25
SCOM AIX Updates (Cert+Agent)
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)][string] $HostName,
[Parameter(Mandatory=$true)][string] $DomainName,
[Parameter(Mandatory=$true)][string] $UserName,
[Parameter(Mandatory=$true)][string] $Password,
[Parameter(Mandatory=$true)]
[ValidateSet("omi","scx")]
[string] $AgentType,
[switch] $WhatIf