Forum Discussion
Kerslock
Jul 21, 2022Copper Contributor
Powershell Command for AD export
I have been searching for info, I am not even sure if what I am doing is feasible. All I want to do is export AD all computers. I have the command "Get-ADComputer -Filter "*" | Export-CSV -Path c:\Us...
farismalaeb
Jul 21, 2022Iron Contributor
HI
Try this code
$allPC=Get-ADComputer -Filter *
$Fullresult=@()
Foreach ($singlePC in $allPC){
$Result=[PSCustomObject]@{
Name=$singlePC.Name
Enabled=$singlePC.Enabled
BIOS=(Get-WmiObject Win32_BIOS -ComputerName $singlePC.name).SerialNumber
}
$Fullresult+=$Result
}
$Fullresult | export-csv -path C:\Myresult.csv
Kerslock
Jul 21, 2022Copper Contributor
- farismalaebJul 24, 2022Iron Contributor
- farismalaebJul 22, 2022Iron Contributor
Use this
$allPC=Get-ADComputer -Filter * $Fullresult=@() $UserNamePassword=Get-Credential Foreach ($singlePC in $allPC){ $Result=[PSCustomObject]@{ Name=$singlePC.Name Enabled=$singlePC.Enabled BIOS=(Get-WmiObject Win32_BIOS -ComputerName $singlePC.name -Credential $UserNamePassword -Authentication Default ).SerialNumber } $Fullresult+=$Result } $Fullresult | export-csv -path C:\Myresult.csv
In line 8, you can replace the authentication with anything that fits your env.
The script asks for a username and password on line 3, just make sure to type it correct.