Hey guys, yesterday I scripted some ps code and got some issues with it, I were able to solve it but I still have some questions in my head which I would like to get answered. I hope somebody can help ![]()
$csv=import-csv -path DEHEREMEX48_gotactivated_listpart.txt -Delimiter “;”
foreach ($line in $csv){
get-aduser -filter {name -like $line.Name} -Properties (‘Name’, ‘co’)| Select Name, co
}
didn’t work, I got an system.Object error why do I have to transform the var using $changeme=line.Name before I’m able to use it in the loop:
foreach ($line in $csv){
$changeme=$line.Name
get-aduser -filter {name -like $changeme} -Properties (‘Name’, ‘co’)| Select Name, co
}
- The output of above delivers a nice table like
name co
xyz DE
yyx DE
Do I use a >> to write the output to a file like:
foreach ($line in $csv){
$changeme=$line.Name
get-aduser -filter {name -like $changeme} -Properties (‘Name’, ‘co’)| Select Name, co >>resul.txt
}
I’m getting a table like this one
name co
xyz DE
name co
yyx DE
I know the workaround is to load the foreachloop into a var. That’s working for me, but I’m still asking myself why I get with the first command a nice table and with the “>>restult.txt” added a really crappy one.
Best Regards,
baschi