Skip to content

Instantly share code, notes, and snippets.

View markwragg's full-sized avatar

Mark Wragg markwragg

View GitHub Profile
@markwragg
markwragg / PRTGPausedDevices.psm1
Last active September 12, 2016 10:25
Powershell module for managing retrieving and removing paused devices from PRTG : http://wragg.io/clean-up-paused-devices-from-prtg-with-powershell/
Function Get-PRTGPausedDevice{
[CmdletBinding()]
Param(
$PRTGURL = "prtg.yourcompany.com",
$Username = "youruser",
$Passhash = "yourpasshash",
$Name,
$Message,
[int]$DaysPaused #Use -1 to filter for where date is unknown and 0 to return all
)
@markwragg
markwragg / Remove-PRTGPausedDevices.ps1
Last active September 12, 2016 10:25
Powershell script to delete multiple devices from PRTG where a name and/or message text is partially matched and where the device is paused and has been paused for longer than x days. The script uses -whatif and -confirm for use with the deletion step.
[CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
Param(
$PRTGURL = "https://{your PRTG URL}/api",
$Auth = "username={your PRTG user}&passhash={your PRTG password hash}",
$Name = "",
$Message = "",
[int]$DaysPaused = 7 #Use -1 to filter for where date is unknown and 0 to return all
)
$Devices = $null
@markwragg
markwragg / Get-Uptime.ps1
Last active September 12, 2016 10:26
Powershell script for getting the uptime of multiple Windows servers using WMI : http://wragg.io/get-uptime-from-multiple-servers/
#Requires -version 2.0
[CmdletBinding()]
param (
[ValidateSet("London","Berlin","Tokyo","")][string]$location
)
Write-Host ("`n" * 5)
Import-Module ActiveDirectory -Cmdlet get-adcomputer
$Servers = get-adcomputer -filter {Enabled -eq $true -and OperatingSystem -Like "Windows*"} -property Enabled,OperatingSystem | ?{$_.DistinguishedName.contains($location)}
@markwragg
markwragg / Sort-ArrayCSV.ps1
Last active September 12, 2016 10:27
Powershell command to sort an array of values and output as a comma separated list.
( @(53,88,135,389,636,3268) | Sort-Object | Out-String | ForEach-Object{$_ -replace '\n', ','} ).TrimEnd(',')
@markwragg
markwragg / Get-PowerShellVersion.ps1
Last active September 12, 2016 10:28
Powershell script to get the installed version of Powershell from multiple servers in an Active Directory domain, optionally filtered by part of an OU name (e.g a location).
#Requires -version 2.0
[CmdletBinding()]
param (
[ValidateSet("Dublin","London”,"Tokyo","Sydney","")][string]$location
)
Import-Module ActiveDirectory -Cmdlet get-adcomputer
$servers = get-adcomputer -filter {Enabled -eq $true -and OperatingSystem -Like "Windows*"} -property Enabled,OperatingSystem | ?{$_.DistinguishedName.contains($location)}
@markwragg
markwragg / Get-PRTGTransactionSensorURLSetting.ps1
Last active September 12, 2016 10:29
Powershell script for getting the URL step settings from all HTTP Transaction sensors in PRTG : http://wragg.io/get-transaction-sensor-url-settings-from-prtg-with-powershell/
[CmdletBinding()]
Param(
$PRTGURL = "https://{your prtg URL}/api",
$Auth = "username={your prtg user}&passhash={your prtg password hash}"
)
$Sensors = ""
$Sensors = (invoke-restmethod "$PRTGURL/table.json?content=sensors&output=json&columns=objid,probe,group,device,sensor,status&count=10000&filter_type=httptransaction&$Auth").sensors
$i = 1
@markwragg
markwragg / RDPUser.psm1
Last active September 13, 2016 15:26
A slightly dirty Powershell module which includes a function for converting the results of the command-line Query User in to a Powershell object and a function for logging off disconnected users (with -whatif and -confirm).
# Example usage:
# Get-RDPUser | Disconnect-RDPUser -WhatIf
Function Get-RDPUser {
[CmdletBinding()]
Param()
query user | Select -Skip 1 | ForEach-Object {
$_ = $_ -split "\s\s+"
@markwragg
markwragg / Get-FolderSize.ps1
Last active October 5, 2016 13:02
Powershell script to get the total size of a list of folders and the last modified date of the newest file in each folder. The script takes a CSV input file which needs to be a list of paths with a header of "path".
[CmdletBinding()]
param (
$Paths = (Import-CSV "Paths.csv")
)
$i = 0
$Total = 0
$Paths | ForEach-Object {
@markwragg
markwragg / Send-Credentials.ps1
Created October 12, 2016 07:53
Powershell script for communicating a list of credentials to users by email. Beware these credentials are therefore communicated in plain text.
[CmdletBinding()]
Param(
[CmdletBinding(SupportsShouldProcess = $true)]
$Inputfile
)
Import-CSV Credentials.csv | ForEach-Object {
$Body = "Dear $($_.GivenName),
@markwragg
markwragg / glossary.ps1
Last active November 11, 2016 16:45
Powershell Azure function for sending messages to Slack
$requestBody = Get-Content $req -raw
$requestBody = $requestBody.Replace('&',"`n")
$requestBody = ConvertFrom-StringData -StringData $requestBody
$Response = (Import-CSV "D:\home\site\wwwroot\Glossary\Glossary.csv") | Where-Object {$_.Term -like "$($requestBody.text)*"}
if(!$Response){Out-File -Encoding Ascii -FilePath $res -inputObject "Sorry, there is no match in the Glossary for *$($requestBody.text)*."}
$Response | ForEach-Object{
Out-File -Encoding Ascii -FilePath $res -inputObject "*$($_.Term):* $($_.Description)" -Append