44 How to export ComputerName from a specific OUs to TXT files?

In the below PowerShell script:-

  1. Name and save the script as “Set-ADComputerList.PS1”.
  2. Create a temp folder into Drive C.
  3. Change the bold items with your OU name in AD where computers are saved.
  4. The output TXT files will be saved to the temp folder for each OU list.
In case of any hurdle, please Contact Us
$LabProdOU = (Get-ADOrganizationalUnit -Filter * | Where-Object {$_.DistinguishedName -like "*Prod*Lab*"}).DistinguishedName
$LabRNDOU = (Get-ADOrganizationalUnit -Filter * | Where-Object {$_.DistinguishedName -like "*RND*Lab*"}).DistinguishedName

$LabProd = (Get-ADComputer -filter {Enabled -eq "True"} -SearchBase $LabProdOU | sort name).name
$LabRND = (Get-ADComputer -filter {Enabled -eq "True"} -SearchBase $LabRNDOU | sort name).name

$LabProd | Out-File -FilePath "C:\Temp\PatchingPROD.txt"

$LabRND | Out-File -FilePath "C:\Temp\PatchingRND.txt"