我只想简单地获取OU中所有用户的所有文件夹
我尝试过Get-ChildItem -path "\\test\foldertest\" -include $users
例如:$user = john.doe, test.2
$users = Get-ADUser -SearchBase "OU=Departed Users,OU=DISABLED,OU=To Decommission,DC=internal,DC=local" -Filter *
Get-childitem -path C:\ -include $users -recurse
我还尝试将其导出到csv并导入,然后运行for-each loop
eg: import-csv C:\test.csv | foreach {get-childitem -path $path}
我应该在$user
变量中获得所有用户名的所有项目/文件夹的列表
答案 0 :(得分:0)
$userlist = "johndoe", "testuser"
foreach ($user in $userlist)
{
$searchfilter = (get-aduser $user | select Samaccountname).Samaccountname
dir $searchfilter
}
我认为这应该有效
答案 1 :(得分:0)
我认为您正在寻找的东西是这样的:
$rootFolder = '\\test\foldertest'
# get a list of all user SamAccountNames in the given OU and wrap these names with asterikses to use as wildcards for '-Include'
$users = Get-ADUser -SearchBase "OU=Departed Users,OU=DISABLED,OU=To Decommission,DC=internal,DC=local" -Filter * |
Select-Object -ExpandProperty SamAccountName | ForEach-Object { "*$_*" }
# next search the rootfolder recursively for any directory where a the name includes a AD SamAccountNames
Get-ChildItem -Path $rootFolder -Directory -Include $users -Recurse | Select-Object -ExpandProperty FullName
如果您怀疑还有我隐藏的文件夹,请将-Force
开关附加到Get-ChildItem
cmdlet。