DSGET输出的结果很少

时间:2016-11-17 10:20:32

标签: powershell dns windows-server-2008 domaincontroller

我们有大约500名用户,我们需要获得完整的列表,包括服务和管理员帐户。

以下示例中的DSQUERY将返回所有用户,但DSGET仅返回大约10个结果。

   $TrafficManagerProfile = Get-AzureRmTrafficManagerProfile -Name "TMName" -ResourceGroupName "TMRGName"
    $publicIPObj = Get-AzureRmPublicIpAddress -ResourceGroupName "App1RGName"
    Add-AzureRmTrafficManagerEndpointConfig -EndpointName "App1" -EndpointStatus Enabled -TargetResourceId $publicIPObj.id -TrafficManagerProfile $TrafficManagerProfile -Type AzureEndpoints -Weight 10
    Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $TrafficManagerProfile
    $TrafficManagerProfile = Get-AzureRmTrafficManagerProfile -Name "TMName" -ResourceGroupName "TMRGName"
    $publicIPObj = Get-AzureRmPublicIpAddress -ResourceGroupName "App2RGName"
    Add-AzureRmTrafficManagerEndpointConfig -EndpointName "App2" -EndpointStatus Enabled -TargetResourceId $publicIPObj.id -TrafficManagerProfile $TrafficManagerProfile -Type AzureEndpoints -Weight 10
    Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $TrafficManagerProfile

为什么会发生这种情况以及如何通过DSGET处理DSQUERY的所有输出?

1 个答案:

答案 0 :(得分:2)

我从未使用过dsquery,但使用PowerShell获取AD中所有用户帐户的列表非常简单。只需更改属性列表以满足您的要求:

Get-ADUser -Filter * -Properties SamAccountName,HomeDrive,HomeDirectory,DistinguishedName | Export-Csv "C:\folder\adusers.csv" -NoTypeInformation

您也可以将输出保存到csv:

Get-ADUser -Filter * -Properties SamAccountName,HomeDrive,HomeDirectory,DistinguishedName | Select SamAccountName,HomeDrive,HomeDirectory,DistinguishedName | Export-Csv "C:\folder\adusers.csv" -NoTypeInformation

编辑:要导出特定属性,您只需在导出为CSV之前选择它们:

$Properties = "SamAccountName,HomeDrive,HomeDirectory,DistinguishedName"
Get-ADUser -Filter * -Properties $Properties | Select $Properties | Export-Csv "C:\folder\adusers.csv" -NoTypeInformation

......或稍微整洁的方式:

Column-1    Column-2    Column-3
A           Val1          Val1
B           Val2          Val2
C           Val3          Val3