运行速度非常慢的 Get-ADUser 阵列 - 我可以加快速度吗?



我已经使用以下代码一段时间了,它可以工作,但需要几个小时才能运行。如果我运行单独的 Get- 命令,我会在几分钟内得到结果,但一旦我在其中添加数组,就会扩展到数小时。

我可能会咬掉比我能咀嚼的更多的东西,因为我对 PS 仍然相当陌生,因为我不需要经常使用它。

Import-Module Activedirectory
$Data=@(
Get-ADUser  -filter * -Properties * |  
Select-Object @{Label = "First Name";Expression = {$_.GivenName}},  
@{Name = "Last Name";Expression = {$_.Surname}},
@{name=  "OU";expression={$_.DistinguishedName.split(',')[1].split('=')[1]}},
@{Name = "Email";Expression = {$_.Mail}},
@{Name = "Account Status";Expression = {if (($_.Enabled -eq 'TRUE')  ) {'Enabled'} Else {'Disabled'}}},
@{Name = "Department";Expression = {$_.Department}}
)
$Data | Export-Csv -Path c:adusers.csv -NoTypeInformation      

只选择你需要的东西会让它走得更快。我将开始在我工作的环境中使用这种方法。我从这个问题中学到了一些东西

Import-Module Activedirectory
$Data=@()
$Data = Get-ADUser -Filter * -Properties "Mail","Department" | 
Select-Object @{Label = "First Name";Expression = {$_.GivenName}},  
@{Name = "Last Name";Expression = {$_.Surname}},
@{Name=  "OU";expression={$_.DistinguishedName.split(',')[1].split('=')[1]}},
@{Name = "Email";Expression = {$_.Mail}},
@{Name = "Account Status";Expression = {if (($_.Enabled -eq 'TRUE')  ) {'Enabled'} Else {'Disabled'}}},
@{Name = "Department";Expression = {$_.Department}}
$Data | Export-Csv -Path c:logsadusers.csv -NoTypeInformation

在几秒钟内运行!

Import-Module Activedirectory
$Data=@(                  
Get-ADUser  -Filter {Enabled -eq $true} -SearchBase “ou=User Accounts,ou=UserAccounts,dc=hiscox,dc=com” -Properties EmailAddress, extensionattribute2 |  
Select-Object @{Label = "First Name";Expression = {$_.GivenName}}, @{Name = "Last Name";Expression = {$_.Surname}}, @{Name = "Email";Expression = {$_.EmailAddress}}, @{Name = "Business Area";Expression = {$_.extensionattribute2}}
)
$Data | Export-Csv -Path c:adusers.csv -NoTypeInformation      

相关内容

最新更新