Hello,
I’m very novice at Powershell and get most of what I would like from browsing Google. I am close to wait i’m trying to achieve but can’t get it complete.
I want to scan AD for all PCs that are like xxxx.
scan a folder on those PCs for child folder a or b or c or d
If folder exists assign a number to each folder
Output computer name and 1 or 2 or 3 or 4.
Below is what i have so far:
$computers = Get-ADComputer -Filter "name -like 'x-ray-*'" |
Foreach ($computer in $computers){
if(Test-Path "\\$computer\c$\programdata\tw\a"){
VALUE = "A"
} elseif (Test-Path "\\$computer\c$\programdata\tw\b"){
VALUE = "B"
} elseif (Test-Path "\\$computer\c$\programdata\tw\c"){
VALUE = "C"
} elseif (Test-Path "\\$computer\c$\programdata\tw\d"){
VALUE = "D"
}}
export-csv c:\users\cn0922\desktop\81003D.csv "$computer, VALUE
I have no error code. I have had a bunch of mixes results trying to get where i want to be and the errors are all different. From error in my code to the output only being the first PC name and the path of the file. That was the closest I came to achieving my goal.
The term VALUE in my code i don’t know what that should be.
Thanks
Olaf, thank you very much. That worked like a charm. I hope to someday have the same understanding of powershell that you have.
I am able to work with this data. this will be very helpful.
if you would like another “challenge”, have the code output a different value.
for example, if $value A exists assign #10 and output computername and #10, or if $value B exists assign #20, etc.