Post

AD Domain Affiliation Check PowerShell

Enabling PowerShell Remoting: In order to use PowerShell Remoting, the Enable-PSRemoting -Force command must be run on each computer. This command makes the necessary settings to establish and manage remote PowerShell sessions.

Firewall Settings: In firewalls such as Windows Firewall, rules must be created that allow PowerShell Remoting traffic. Otherwise, remote connections may fail.

Permissions: You must have the necessary permissions to run this script. In particular, you must have permission to read computer objects in Active Directory (to be able to run the Get-ADComputer command)

# Get computers in OU
$computers = Get-ADComputer -SearchBase "OU=uyeler,DC=guler,DC=com" -Filter * | Select-Object -ExpandProperty Name

# Check every computer
foreach ($computer in $computers) {
try {
$session = New-PSSession -ComputerName $computer -ErrorAction Stop
Remove-PSSession $session
Write-Host "${computer}: Connected to Domain"
} catch {
Write-Host "${computer}: Not connected to Domain" }}
This post is licensed under CC BY 4.0 by the author.