使用 Quest powershell cmdlet 更改 Active Directory 中用户的个人资料信息

发布于 2024-12-21 07:12:35 字数 592 浏览 0 评论 0原文

尝试循环遍历活动目录中的 OU,然后更改该 OU 中所有用户的配置文件下的 HomeDirectory 和 HomeDrive。我遇到的唯一问题是当我在 HomeDirectory 的路径中使用环境变量 %USERNAME% 时,它无法正确映射。它将映射到 home 文件夹,但不会映射到 %USERNAME%。如何让它映射到 %USERNAME% 文件夹?我使用了错误的变量吗?非常感谢任何帮助。下面是我的 powershell 代码:

    #Add Snapin for Get-QADuser
    Add-PSSnapin Quest.ActiveRoles.ADManagement

    #Set OU variable
    set-variable -name OU -value "domain.local/Test"

    #Get members of OU then set HomeDirectory and HomeDrive of each user in OU
    get-qaduser -searchroot $OU | set-QADUser -HomeDirectory '\\server\homes\%USERNAME%' -HomeDrive 'H:'

Trying to loop through an OU in active directory and then change the HomeDirectory and HomeDrive under profile for all users in said OU. The only problem I have is when I use the environment variable %USERNAME% in the path of the HomeDirectory it doesn't map correctly. It will map to the homes folder, but not to the %USERNAME%. How do I get it to map down to the %USERNAME% folder? Am I using the wrong variable? Any help is greatly appreciated. Here's my powershell code below:

    #Add Snapin for Get-QADuser
    Add-PSSnapin Quest.ActiveRoles.ADManagement

    #Set OU variable
    set-variable -name OU -value "domain.local/Test"

    #Get members of OU then set HomeDirectory and HomeDrive of each user in OU
    get-qaduser -searchroot $OU | set-QADUser -HomeDirectory '\\server\homes\%USERNAME%' -HomeDrive 'H:'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-12-28 07:12:35

您需要使用每个传入用户帐户的 SamAccountName

Get-QADUser -SearchRoot $OU | Foreach-Object{
    Set-QADUser -Identity $_ -HomeDirectory "\\server\homes\$($_.SamAccountName)" -HomeDrive 'H:'
}

You need to use the SamAccountName of each incoming user account

Get-QADUser -SearchRoot $OU | Foreach-Object{
    Set-QADUser -Identity $_ -HomeDirectory "\\server\homes\$($_.SamAccountName)" -HomeDrive 'H:'
}
衣神在巴黎 2024-12-28 07:12:35

你必须这样做:

"\\server\homes\$env:USERNAME"

请注意,它也是双引号而不是单引号。

You have to do it like this:

"\\server\homes\$env:USERNAME"

Note that it is double quotes as well and not single.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文