Skip to content

Instantly share code, notes, and snippets.

<#
.DESCRIPTION
Microsoft recommended database maintenance script
"The performance of large Windows Server Update Services (WSUS) deployments will degrade over time if the WSUS database
is not maintained properly. The WSUSDBMaintenance script is a T-SQL script that can be run by SQL Server administrators
to re-index and defragment WSUS databases. It should not be used on WSUS 2.0 databases.This script contributed by the
Microsoft WSUS team."
Reference: https://support.microsoft.com/en-us/help/4490644/complete-guide-to-microsoft-wsus-and-configuration-manager-sup-maint
$currentIdentity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
$isAdministrator = $currentIdentity.IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')
if (-not $isAdministrator) {
$Arguments = ('& ''{0}''' -f $MyInvocation.MyCommand.Definition)
Start-Process PowerShell.exe -Verb RunAs -ArgumentList $Arguments
break
}
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
function Hide-ConsoleWindow
{
$consolePtr = [Console.Window]::GetConsoleWindow()
#requires -Version 5
#requires -PSEdition Desktop
class TrustAllCertsPolicy : System.Net.ICertificatePolicy {
[bool] CheckValidationResult([System.Net.ServicePoint] $a,
[System.Security.Cryptography.X509Certificates.X509Certificate] $b,
[System.Net.WebRequest] $c,
[int] $d) {
return $true
}
Function Test-ServerSSLSupport
{
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[String]$HostName,
[UInt16]$Port = 443
)
Function Get-WiFiNetworks {
$RegEx =
@'
(?x)
SSID\s\d+\s:\s(?<SSID>[a-z0-9\-\*\.&_]+)\r\n
Network\stype\s+:\s(?<NetworkType>\w+)\r\n
Authentication\s+:\s(?<Authentication>[a-z0-9\-_]+)\r\n
Encryption\s+:\s(?<Encryption>\w+)\r\n
BSSID\s1\s+:\s(?<BSSID>(?:\w+:){5}\w+)\r\n
Signal\s+:\s(?<Signal>\d{1,2})%\r\n
# https://powershell.one/code/11.html
Function Invoke-WakeOnLan
{
param
(
# one or more MACAddresses
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
# mac address must be a following this regex pattern:
[ValidatePattern('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$')]
# https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/final-super-fast-ping-command
Function Test-OnlineFast
{
param
(
# make parameter pipeline-aware
[Parameter(Mandatory,ValueFromPipeline)]
[string[]]
$ComputerName,
function Send-Ping()
{
[CmdletBinding(DefaultParametersetName="p1")]
Param
(
[Parameter(ParameterSetName="p1", Mandatory = $true, Position = 0, ValueFromPipeline = $true,
HelpMessage = "One or more remote hosts to ping.")]
[String[]] $RemoteHost,
[Parameter(ParameterSetName="p2", Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true,
Function Get-DfsnFolderTargetsRecursive
{
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $DFSPath
)
Write-Progress "Getting all DFS folders for $DFSPath (this can take a very long time)" -PercentComplete -1