Récupérer la liste des machines d’un AD en powershell

const FileName ="liste_machine_ad.csv"
set cmd = createobject("ADODB.Command")
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")
 
cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn
 
set objRoot = getobject("LDAP://RootDSE")
 
cmd.commandtext = "<LDAP://" & objRoot.get("defaultNamingContext") & ">;(objectCategory=Computer);" & "name,distinguishedName;subtree"
cmd.properties("page size")=1000
 
set rs = cmd.execute
set objFSO = createobject("Scripting.FileSystemObject")
set objCSV = objFSO.createtextfile(FileName)
 
q = """"
 
while rs.eof <> true and rs.bof <> true
    objcsv.writeline(q & rs("name") & q & ";" &  q & rs("distinguishedName") & q)
    rs.movenext
wend
 
objCSV.Close
cn.close
 
wscript.echo "La génération de la liste des ordinateurs est terminée"