Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 获取OU中每个广告组的所有成员_Powershell_Active Directory - Fatal编程技术网

Powershell 获取OU中每个广告组的所有成员

Powershell 获取OU中每个广告组的所有成员,powershell,active-directory,Powershell,Active Directory,我是Powershell和AD的新手。我面临的挑战是能够查询OU以检索该OU中的所有组,然后检索每个组的所有成员。我目前拥有以下脚本,可以执行此操作: $Groups = Get-ADGroup -Filter * -SearchBase "OU=xx,OU=xx xx,DC=xx,DC=xx" -SERVER "xxxxxx" #creates a variable with the name Groups and stores all the groups into it $Results

我是Powershell和AD的新手。我面临的挑战是能够查询OU以检索该OU中的所有组,然后检索每个组的所有成员。我目前拥有以下脚本,可以执行此操作:

$Groups = Get-ADGroup -Filter * -SearchBase "OU=xx,OU=xx xx,DC=xx,DC=xx" -SERVER "xxxxxx" #creates a variable with the name Groups and stores all the groups into it

$Results = foreach( $Group in $Groups ){ #looks for members in each group and stores them in Results
    Get-ADGroupMember -Identity $Group -SERVER "xxxxxx" | Select distinguishedName | foreach {
        [pscustomobject]@{
            GroupName = $Group.Name
            Name = $_
        }
    }
}

$Results| sort -Property GroupName | Export-Csv -Path c:\Temp\groups.csv -NoTypeInformation #stores results in a csv

我遇到的问题是,我需要能够在一行中执行相同的操作,以便运行它并将其拉回到Excel中(用于报告)。由于签名,我无法从Excel执行脚本,但我可以执行一行。如果您有任何建议,我们将不胜感激

您可以使用
EncodedCommand
选项:

$ScriptText  = Get-Content C:\Path\To\Script.ps1 -Raw
$ScriptBytes = [System.Text.Encoding]::Unicode.GetBytes($ScriptText)
$EncCommand  = [System.Convert]::ToBase64String($ScriptBytes)
现在复制
$EncCommand
(例如使用
$EncCommand |设置剪贴板
)的内容,并将生成的base64字符串作为命令行参数提供给
encodeCommand
命令行开关:

powershell.exe -EncodedCommand JABHAHIAbwB1AHAAcwAgAD0AIABHAGUAdAA...

“由于签名,我无法从Excel执行脚本”-是的,您可以。只需在
powershell.exe
命令行上使用
-ExecutionPolicy Bypass
。@Bill\u Stewart。我不知道如何做到这一点,除了在3行中(旁路、调用脚本、重置)。现在运行它,它似乎正在工作!