by tommls at 2013-03-01 07:50:28
Can I do this?? Or should it be done differently??by tommls at 2013-03-01 08:05:27
foreach $($.name) # each domain user ID (possible to specify only users in Domain Users group??)
{
# do code e.g.
Set-Location "\$server\C$\Users\$_.name\AppData\Local\Temp" -ErrorAction SilentlyContinue<br>} # end foreach<br><br>Thank you, Tom</blockquote>by mjolinor at 2013-03-01 08:03:12<blockquote><code>$users = <command that gets a list of user names><br><br>foreach ($user in $users)<br> {<br> # do code e.g.<br> Set-Location "\\$server\C$\Users$user\AppData\Local\Temp" -ErrorAction SilentlyContinue
}
See get-help about_foreach
Or use the pipeline with foreach-object:$user = <command that gets a list of user names>
$users |
foreach-object {
# do code e.g.
Set-Location "\$server\C`$\Users$\AppData\Local\Temp" -ErrorAction SilentlyContinue
}
Note the difference in the way the user object is referenced ($_ in the pipeline, and $user in the foreach loop)
What command gets the user’s ID (aka SAM Account Name)??by mjolinor at 2013-03-01 08:10:01
I’m now trying to figure this out…
Thank you, Tom
If you have the RSAT tools installed (with the ActiveDirectory module)by tommls at 2013-03-01 08:24:29Get-ADUser | select -ExpandProperty sAMAccountName
That doesn’t work because it doesn’t get ALL users and requests a filter which I tried including…by mjolinor at 2013-03-01 08:48:19
e.g. Get-ADUser | select -ExpandProperty sAMAccountName -Filter * -SearchBase "OU=Domain Users,DC=foo,DC=local" does not work but it is the gist of what I want…It absolutely must select only Domain Users.
This command must be set equal to $users to create an array of user IDs.
$Users = Get-ADUser -Filter * -SearchBase "OU=Domain Users,DC=foo,DC=local" |
select -ExpandProperty SamAccountNameby tommls at 2013-03-01 09:20:53I had tried that command but I now realize I had the filter/search and search reversed because I did not fully understand the order of things in the docs.
Thank you!!Tom