简体   繁体   中英

How can I turn this power shell command for Active Directory into a 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

When I run the command, nothing happens in PowerShell.

You've used my suggestion wrong, either assign the output from Read-Host to a variable:

$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

Or use it inline:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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