Skip to content

Instantly share code, notes, and snippets.

View AshFlaw's full-sized avatar

AshFlaw

  • The Full Circle
View GitHub Profile
@AshFlaw
AshFlaw / CredentialObjectOneLine.ps1
Created June 28, 2018 11:25
A one line command to get a full (username and password) credential object without bringing them in from variables.
$Credential = New-Object System.Management.Automation.PSCredential 'username',(convertto-securestring 'password' -asplaintext -force)
@AshFlaw
AshFlaw / Get-AvailableRAM.ps1
Created July 17, 2018 09:13
Get available RAM on a remote server via powershell
$Server = ""
(Get-Counter -Counter "\Memory\Available MBytes" -ComputerName $Server).CounterSamples[0].CookedValue
@AshFlaw
AshFlaw / Set-EolMailBoxAuditEnabledAll.ps1
Created July 19, 2018 06:48
Enable Exchange Online mailbox auditing manually for all mailboxes
Get-Mailbox -Filter {AuditEnabled -eq $False} -RecipientTypeDetails UserMailbox, SharedMailbox | Set-Mailbox -AuditEnabled $True –AuditDelegate Create, FolderBind, SendAs, SendOnBehalf, SoftDelete, HardDelete, Update, Move, MoveToDeletedItems, UpdateFolderPermissions
@AshFlaw
AshFlaw / EOL-MailBoxAuditing.ps1
Created July 19, 2018 08:16
Check, enable and disable Tenant level mailbox auditing in Exchange Online
# Get Auditing Status
Get-OrganizationConfig | Select AuditDisabled
# Disable Auditing for Tenant
Set-OrganizationConfig -AuditDisabled $True
# Disable Auditing for User
Set-MailboxAuditBypassAssociation -Identity $User -AuditBypassEnabled $True
# Find Mailboxes with Audting Disabled
@AshFlaw
AshFlaw / CopyADGroupMemberships.ps1
Created July 19, 2018 08:17
Copy AD group memberships from one user account to another.
$Source = ""
$Destination = ""
Get-ADUser -Identity $Source -Properties memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $Destination
@AshFlaw
AshFlaw / install-GPMC.ps1
Created August 15, 2018 16:42
Install Group Policy Management Console, GPMC via PowerShell
Install-WindowsFeature –Name GPMC
@AshFlaw
AshFlaw / Add-OMSNetworkMonitoringFirewallRules.ps1
Created September 12, 2018 07:12
Bulk add the OMS Log Analytics Network Monitoring rules to all machines in a domain
Function OMSICMPFWRules
{
netsh advfirewall firewall add rule name="NPMDICMPV4Echo" protocol="icmpv4:8,any" dir=in action=allow
netsh advfirewall firewall add rule name="NPMDICMPV6Echo" protocol="icmpv6:128,any" dir=in action=allow
netsh advfirewall firewall add rule name="NPMDICMPV4DestinationUnreachable" protocol="icmpv4:3,any" dir=in action=allow
netsh advfirewall firewall add rule name="NPMDICMPV6DestinationUnreachable" protocol="icmpv6:1,any" dir=in action=allow
netsh advfirewall firewall add rule name="NPMDICMPV4TimeExceeded" protocol="icmpv4:11,any" dir=in action=allow
netsh advfirewall firewall add rule name="NPMDICMPV6TimeExceeded" protocol="icmpv6:3,any" dir=in action=allow
}
@AshFlaw
AshFlaw / Invoke-DisconnectedRDPSessionLogOff.ps1
Created September 30, 2018 19:19
Remotely log off all disconnected sessions from a server, RDP session hosts or otherwise.
$server = ''
$sessions = quser /server:$server | where-object { $_ -match "Disc" }
Foreach ($Session in $Sessions)
{
$UserName = $Session.split(' +')[1]
$ID = qwinsta /server:$server $UserName | where-object { $_ -match $UserName } | Where { $_ -ne "" } | ForEach { $_.Replace(" ","") } | ForEach { $_.Replace("Disc","") } | ForEach { $_.ToLower() } | ForEach { $_.Replace("$UserName","") }
Write-Output "SessionID $ID Username: $UserName is disconnected"
logoff $ID /server:$server
}
@AshFlaw
AshFlaw / Remove-SSLNagScreenPRTG.ps1
Last active October 7, 2018 06:49
Remove the SSL reminder screen in PRTG. Useful for reverse proxy situations when the proxy is SSL but the internal termination is HTTP.
Write-Output "Stopping PRTG Core Service"
Get-Service -Name prtgcoreservice | Stop-Service
Write-Output "Disabling SSL nag message in UI"
Set-ItemProperty -path "HKLM:\SOFTWARE\Wow6432Node\Paessler\PRTG Network Monitor\Server\Webserver" -Name "showsslnagscreen" -value 0
Write-Output "Starting PRTG Core Service"
Get-Service -Name prtgcoreservice | Start-Service
@AshFlaw
AshFlaw / Set-WindowsFirewallPortsShazamDiscovery.ps1
Created November 16, 2018 16:59
Configure windows firewall to allow Shazam probe discovery
$Servers = Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select-Object -Expand DNSHostName
Foreach ($Server in $Servers)
{
invoke-command -ComputerName $Server -ScriptBlock {Set-NetFirewallRule -DisplayGroup 'Remote Event Log Management' -Enabled True -PassThru -EdgeTraversalPolicy Allow | Select-Object DisplayName, Enabled}
invoke-command -ComputerName $Server -ScriptBlock {Set-NetFirewallRule -DisplayGroup "Windows Management Instrumentation (WMI)" -Enabled True -PassThru -EdgeTraversalPolicy Allow -ErrorAction SilentlyContinue | Select-Object DisplayName, Enabled}
}