Skip to content

Instantly share code, notes, and snippets.

View iyre's full-sized avatar

Miles Miller iyre

View GitHub Profile
@iyre
iyre / Edit-RdpPort.ps1
Last active November 28, 2021 05:36
Remotely manipulate RDP port assignments with PowerShell
Function Edit-RdpPort {
<#
.SYNOPSIS
Changes the port assigned to RDP
.DESCRIPTION
Change the port assigned to RDP by updating the registry and restarting relevant services
.PARAMETER ComputerName
ComputerName that will have its port changed
.PARAMETER Port
New port number
@iyre
iyre / Set-ThisPcLibrary.ps1
Last active February 22, 2020 19:48
Add or remove libraries listed in 'This PC'
### Usage:
## Import functions
# >. .\Set-ThisPcLibrary.ps1
## Add library to 'This PC'
# >Set-ThisPcItem pictures
# Pictures
## Remove specific library
# >Set-ThisPcItem -Remove pic
# Pictures
## Remove all libraries
@iyre
iyre / QueryCpuSpec.ps1
Created February 18, 2020 19:33
Query computers in domain for processor specifications
# duplicates indicate multiple processors
$Search = "OU=Domain servers,dc=contoso,dc=com"
Get-ADComputer -filter * -SearchBase $Search | Foreach-Object {
$property = "systemname","maxclockspeed","addressWidth","numberOfCores","NumberOfLogicalProcessors"
Get-WmiObject -computername $_.name -class win32_processor -Property $property -erroraction silentlycontinue | Select-Object -Property $property
}
@iyre
iyre / New-HardwareReport.ps1
Last active September 23, 2022 19:31
Queries system properties using WMI and exports findings to an HTML file
<#
.SYNOPSIS
Generates a report of system configuration
.DESCRIPTION
Queries system properties using WMI and exports findings to an HTML file
.PARAMETER ComputerName
Specifies target. Defaults to local hostname
.PARAMETER FilePath
Specifies output path. Defaults to current location
.PARAMETER Open
@iyre
iyre / FindExpiringPasswords.ps1
Created February 18, 2020 22:39
Query AD for expiring passwords
$ExcludeDays = 90 # Exclude if password changed in the last $ days
$CutoffDate = (Get-Date).adddays(-($ExcludeDays))
$Users = Get-ADUser -filter {
Enabled -eq $True -and
PasswordNeverExpires -eq $False -and
PasswordLastSet -lt $CutoffDate
} -Properties msDS-UserPasswordExpiryTimeComputed, PasswordLastSet, CannotChangePassword
$Users | Sort-Object -Property msDS-UserPasswordExpiryTimeComputed | Select-Object Name, PasswordLastSet,
@{ Name="ExpiryDate";Expression={ [datetime]::FromFileTime( $_."msDS-UserPasswordExpiryTimeComputed" ) } }
@iyre
iyre / FindSharedPrinters.ps1
Created February 18, 2020 22:59
Check the registry for shared printers
$ComputerName = Read-Host -Prompt 'Host'
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
Get-ChildItem Registry::\HKEY_Users |
Where-Object { $_.PSChildName -notmatch ".DEFAULT|S-1-5-18|S-1-5-19|S-1-5-20|_Classes" } |
Select-Object -ExpandProperty PSChildName |
ForEach-Object { Get-ChildItem Registry::\HKEY_Users\$_\Printers\Connections -Recurse | Select-Object }
}
@iyre
iyre / ClearStuckPrintQueue.ps1
Last active February 20, 2020 16:37
Remotely clear print queue and restart spooler
$ComputerName = Read-Host -Prompt 'Target'
$Cred = Get-Credential -Credential $null
Write-Host "Opening session with remote host"
$Session = New-PSSession -ComputerName $ComputerName -Credential $Cred -ErrorAction Stop
$Confirm = Read-Host "Are you sure that you want to delete all print jobs on $ComputerName (Y/N)"
if ( $Confirm -eq 'Y' ) {
Write-Host "1. Stopping spooler" -ForegroundColor Green
@iyre
iyre / ListActiveComputers.ps1
Created February 18, 2020 23:31
Get a list of active domain computers
$DateOffset = 30
$StartDate = (Get-Date).adddays(-($DateOffset))
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com"
Get-ADComputer -Filter {
( LastLogonDate -gt $StartDate ) -and
( Name -ne "$env:COMPUTERNAME" )
} -SearchBase $SearchBase -Properties LastLogonDate |
Sort-Object -Property LastLogonDate |
Format-Table -Property Name, LastLogonDate
@iyre
iyre / SutdownActiveComputers.ps1
Created February 18, 2020 23:41
Remotely shut down all active computers on a domain
# Shuts down computers without notice
$DateOffset = 30
$StartDate = (Get-Date).AddDays(-($DateOffset))
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com"
Get-ADComputer -Filter {
( LastLogonDate -gt $StartDate ) -and
( Name -ne "$env:COMPUTERNAME" )
} -SearchBase $SearchBase -Properties LastLogonDate |
@iyre
iyre / KillProcessActiveComputers.ps1
Last active July 31, 2020 20:08
Invoke commands on all active computers in a domain
$ProcessName = "outlook"
$DateOffset = 30
$StartDate = (Get-Date).AddDays(-($DateOffset))
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com"
Get-ADComputer -Filter {
( LastLogonDate -gt $StartDate ) -and
( Name -ne "$env:COMPUTERNAME" )
} -SearchBase $SearchBase |
Foreach-Object {