简体   繁体   English

与Get-ADUser相关的查询

[英]Query Related to Get-ADUser

What is the best way to create a powershell script to search the entire AD users to get the list of users that does not have a home directory or home drive assigned in its properties, and save its samaccountname in a variable stack and by looping through each name - create its home drive folder 创建Powershell脚本以搜索整个AD用户以获取在其属性中未分配主目录或主驱动器的用户列表,并将其samaccountname保存在变量堆栈中并通过循环遍历每个用户的最佳方法是什么?名称-创建其主驱动器文件夹

THIS WOULD BE LIKE THIS I SUPPOSE 这将像我所建议的那样

 $c = get-ADUser -filter * -searchbase -properties 
    foreach($b in $c)
    {
    New-item -path
    }

can someone help? 有人可以帮忙吗?

You can use this: 您可以使用此:

$SAMs = Get-ADUser -filter * -Properties ProfilePath | ? {$_.ProfilePath -eq $Null} | Select SamaccountName

foreach ($SAM in $SAMs)
{
$NewDir = New-Item $SAM -Type Directory -Path "ChooseYourPath" ## Create the Folder in desired path
Set-ADUser $SAM -ProfilePath $NewDir.FullName ## Set the AD User Account ProfilePath Property with the New Folder
}

Use the LDAPFilter parameter to find all the users who have no or blank home directory attributes: 使用LDAPFilter参数查找没有或空白主目录属性的所有用户:

Get-ADUser -LDAPFilter "(!(profilePath=*))" | ForEach-Object {
    $Username = $_.SAMAccountName
    $NewHomeDir = New-Item -Path "\\homedir\root\path" -ItemType Directory -Name $Username
    if($?){
        Set-ADUser $_ -ProfilePath $NewHomeDir.FullName
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM