主文件夹重新映射与电源shell

时间:2017-10-13 09:42:24

标签: powershell-v3.0

我试图将所有用户的主驱动器从DC1重新映射到DC2,但它失败了。有谁会注意到它的错误?

$users=Get-ADUser -Filter {sAMAccountName -eq "user1"} -SearchBase 'OU=xxx,DC=ad,DC=xxx,DC=com' -properties * | Where-Object { $_.HomeDirectory -like "*DC1*" } 
ForEach( $user in $users) { 
    $HomeDirectory=$user.HomeDirectory.ToLower()
    $newHomeDirectory=$HomeDirectory.replace("DC1", "DC2")
    Set-AdUser -Identity $user -HomeDirectory $newHomeDirectory
    "$newHomeDirectory set for user $($user.name) ($($user.SamAccountName))"
}

我还尝试使用以下电源shell从DC1中删除主驱动器(它没有返回任何错误,但也没有删除文件夹):

$mapped = Get-WmiObject Win32_MappedLogicalDisk | Select DeviceId, ProviderName
foreach ($item in $mapped) {
    if ($item.ProviderName -eq '\\DC1\users\$env:username') {net use $item.DeviceId /del}
}

0 个答案:

没有答案