PowerShell Commands




Space for me to record any used PowerShell commands and their usages



Commands learned from:

https://www.reddit.com/r/PowerShell/comments/1f1v531/powershell_cheat_sheet/

https://www.ninjaone.com/blog/windows-powershell-commands-cheat-sheet/


Server Configuration

Set Computer Name

Rename-Computer -NewName "DC01" -Restart

Set Time Zone

Set-TimeZone -Name "Eastern Standard Time"

Enable Remote Desktop

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

Get Current Network Adapter Info

Get-NetAdapter
Get-NetIPAddress

Remove DHCP Configuration

Remove-NetIPAddress -InterfaceAlias "Ethernet" -Confirm:$false
Remove-NetRoute -InterfaceAlias "Ethernet" -Confirm:$false

Set Static IP Address

New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 192.168.1.10 -PrefixLength 24 -DefaultGateway 192.168.1.1

Set DNS Servers

Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 127.0.0.1, 8.8.8.8

Verify Network Configuration

Get-NetIPConfiguration -InterfaceAlias "Ethernet"
Test-NetConnection -ComputerName google.com


Install DHCP Server Role

Install-WindowsFeature DHCP -IncludeManagementTools

Add DHCP Server Security Groups

Add-DhcpServerSecurityGroup

Authorize DHCP Server in AD

Add-DhcpServerInDC -DnsName "DC01.corp.contoso.com" -IPAddress 192.168.1.10

Configure DHCP Server Settings

Set-DhcpServerv4OptionValue -DnsServer 192.168.1.10 -DnsDomain "corp.contoso.com"


Add new user to OU

New-ADUser -Name "Bob Smith" -SamAccountName "bsmith" -UserPrincipalName "bsmith@yourdomain.local" -Path "OU=TestUsers,OU=LAB,DC=yourdomain,DC=local" -AccountPassword (ConvertTo-SecureString "P@ssw0rd123!" -AsPlainText -Force) -Enabled $true


Add new group to OU

New-ADGroup -Name "LAB-Admins" -GroupScope Global -GroupCategory Security -Path $groupPath -Description "Lab Administrator Group"

define: $groupPath = "OU=Groups,OU=LAB,DCyourdomain,DC=local"


Add user “Bob Smith” to LAB-Admins

Add-ADGroupMember -Identity "LAB-Admins" -Members "bsmith"

# Check what GPOs apply to a user

gpresult /r /user:yourdomain\bsmith

# Force GPO update

gpupdate /force

# See GPO application for specific computer

Get-GPResultantSetOfPolicy -Computer "TestPC1" -User "yourdomain\intern1"

# Test which GPOs are linked to an OU

Get-GPInheritance -Target "OU=Restricted-Users,OU=GPO-Testing,DC=yourdomain,DC=local"

# Check security filtering

Get-GPPermission -Name "PowerUser-Rights" -All