如何将Active Directory的此Power Shell命令转换为批处理文件?

时间:2018-06-25 15:30:21

标签: powershell batch-file

-groupname (Read-Host "Enter Group Name") 
Get-ADGroupMember -Identity "groupname" -Recursive |
    Get-ADUser -Properties mail |
    Select-Object Name,mail |
    Export-Csv -Path C:\Users\user\OneDrive\groupname.csv

当我运行命令时,在PowerShell中什么也没发生。

1 个答案:

答案 0 :(得分:1)

您使用我的建议有误,可以将Read-Host的输出分配给变量:

$groupname = Read-Host "Enter Group Name"
Get-ADGroupMember -Identity $groupname -Recursive |
    Get-ADUser -Properties mail |
    Select-Object Name,mail |
    Export-Csv -Path C:\Users\user\OneDrive\groupname.csv

或内联使用:

Get-ADGroupMember -Identity (Read-Host "Enter Group Name") -Recursive |
    Get-ADUser -Properties mail |
    Select-Object Name,mail |
    Export-Csv -Path C:\Users\user\OneDrive\groupname.csv