Skip to main content

Quick commands (Windows)

Nameresolution via other server than default

nslookup some.dns.server

Get Windows client join status

dsregcmd /status

Get applied GPO status on Windows client

gpresult /h C:\LocalData\GPResult.html

Get RDS license status

(Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).__PATH -name GetGracePeriodDays).daysleft
wmic /namespace:\\root\CIMV2\TerminalServices PATH Win32_TerminalServiceSetting WHERE (__CLASS !="") CALL GetGracePeriodDays

Rejoin device to Microsoft Entra ID

dsregcmd /forcerecovery

Delete specific files recursive

$source = "<sourcepath>"
$fileextension = "<filextension>"
get-childitem $source -include *$fileextension | foreach ($_) {remove-item $_.fullname}

Run PowerShell as admin from different session

Start-Process PowerShell -verb runas

Get last reboot time

Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}

Set error action in PowerShell session

$erroractionpreference = "silentlycontinue"

Test network connection

Test TCP port

Test-NetConnection -ComputerName <youripaddress> -Port <yourport>
$ipaddress = "<youripaddress>"
$port = "<yourport>"
$connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
if ($connection.Connected) {
     Write-Host "Success" 
} else { 
     Write-Host "Failed" 

Test UDP port

$ipaddress = "<youripaddress>"
$port = "<yourport>"
$connection = New-Object System.Net.Sockets.UdpClient($ipaddress, $port)
if ($connection.Connected) {
     Write-Host "Success" 
} else { 
     Write-Host "Failed" 

Manage Local Windows Groups

Add Microsoft Entra ID user to administrator group

$Email = ""
Add-LocalGroupMember -SID "S-1-5-32-544" -Member "AzureAD\$EMail"

Add Microsoft Entra ID user to remote desktop group

$Email = ""
Add-LocalGroupMember -SID "S-1-5-32-555" -Member "AzureAD\$EMail"

Open Windows Control Panel pages

Printer overview

explorer shell:PrintersFolder

PowerShell Module Management

List installed modules