Skip to content

Instantly share code, notes, and snippets.

View markwragg's full-sized avatar

Mark Wragg markwragg

View GitHub Profile
@markwragg
markwragg / Test-TestNetConnection.ps1
Last active April 12, 2019 12:06
Powershell snippets to test functionality of the test-NetConnection cmdlet.
#Performs a simple Ping test to the default destination of internetbeacon.msedge.net
Test-NetConnection
#Performs a Ping test to google.com
$Ping = Test-NetConnection -ComputerName google.com | Select *
#Performs a Traceroute test to google.com
$TraceRt = Test-NetConnection -ComputerName google.com -TraceRoute
$TraceRt | Select *
@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 / 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 / Test-Pester.tests.ps1
Last active May 1, 2022 20:12
Powershell pester script with various examples of using pester for operational validation.
Describe 'My process checks' {
Context 'Checking essential Windows processes are running' {
It 'winlogon.exe is running' {
get-process -Name 'winlogon' | Should be $true
}
}
@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 / Remove-OldFiles.ps1
Last active November 6, 2022 21:54
Powershell script to remove files older than a certain date and log the files removed to a file.
[CmdletBinding()]
Param(
$limit = (Get-Date).AddDays(-7),
$path = "C:\Example\Path"
)
# Delete files older than the $limit.
$FilesToDelete = (Get-ChildItem -Path $path -Exclude Logs | Where-Object { $_.LastWriteTime -lt $limit }) | Select Path
# If files are deleted create a log detailing this
@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 / SEP.tests.ps1
Last active May 22, 2019 19:33
Pester tests for Symantec Endpoint Protection to perform operational validation of configuration and health.
Param(
$SEPLatestVersion = "12.1.7"
)
Describe 'Symantec Endpoint Protection checks' {
Context 'SEP service checks' {
$SEPServices = @('SepMasterService','SmcService')
@markwragg
markwragg / Audit-Computer.ps1
Created November 8, 2016 10:41
Pester tests for validating the configuration of a server matches the configuration captured previously (e.g prior to a change).
Get-WmiObject Win32_logicaldisk | Export-Clixml "$env:computername-LogicalDisks.xml"
(Get-Service | select name,displayname,status) | Export-Clixml "$env:computername-Services.xml"
(Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.IPEnabled -eq "True"}) | Export-Clixml "$env:computername-Network.xml"
@markwragg
markwragg / Glossary.psm1
Last active November 11, 2016 20:11
A Powershell Module that includes a function for searching a CSV file which is a Glossary of terms and presents the results in a variety of formats.
<#
.Synopsis
Glossary Module
.DESCRIPTION
A Powershell Module that includes a function for searching a CSV file which is a Glossary of terms and presents the results in a variety of formats.
.EXAMPLE
Search-Glossary MyTerm
.EXAMPLE
Search-Glossary MyTerm -PassThru | Export-CSV MyTerms.csv
#>