powershell - Errors in listing AD groups for AD PCs -
i writing script work , trying determine why code showing errors. new coding , want understand wrong.
the errors tag .... pc listings in .txt file.
ex: get-content : cannot find path 'f:\tag 77909' because not exist. confusion when write-host after .replace code prints correctly
ex:you cannot call method on null-valued expression. + $notags =$pc.replace <<<< ("tag ", "pc") + categoryinfo : invalidoperation: (replace:string) [], runtimeex ception + fullyqualifiederrorid : invokemethodonnull
last error prints out last pc.... id in .txt file listing??? unsure why given have foreach loop
**my code far:** import-module activedirectory $compimports = get-content "c:\temp\temp\input.txt" $groupexport = "c:\temp\temp\output.txt" clear-content $groupexport $header = "pc name" + "|" + "group name" + "|" + "group description" #write header $header | out-file $groupexport -append #get pc tag listing $pcs = get-content $compimports #for loop change "tag " "pc" foreach($pc in $pcs) { $notags =$pc.replace("tag ", "pc") } #loop information , print out foreach ($notag in $notags) { $computerobj = get-adcomputer $notag -properties memberof $computerobj.memberof | ? {$_ -match '^cn=app.*'} ` | % {get-adgroup $_ -properties name, description} | ` % {$computerobj.name + "|" + $_.name + "|" + $_.description ` | out-file $groupexport -append} }
i see @ least 1 issue here
$compimports = get-content "c:\temp\temp\input.txt" ... $pcs = get-content $compimports
you calling get-content
twice generate error seeing likely. simplified
$pcs = get-content "c:\temp\temp\input.txt"
your other error should go away result since $pcs should contain real data @ point.
Comments
Post a Comment