Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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从循环中提取_Powershell - Fatal编程技术网

powershell从循环中提取

powershell从循环中提取,powershell,Powershell,我有下面的脚本 Switch -Wildcard ("$($group)$($action)") { "Citrix*" {$GroupC = ("#GG-$CC--Citrix1","#GG-$CC-Citrix2-","#GG-$CC-Citrix3")} } If ($group -eq "Citrix"){ $Response = New-Object System.Collections.ArrayList $DateInFuture = Read-Host

我有下面的脚本

Switch -Wildcard ("$($group)$($action)") {
    "Citrix*" {$GroupC = ("#GG-$CC--Citrix1","#GG-$CC-Citrix2-","#GG-$CC-Citrix3")}
}

If ($group -eq "Citrix"){
    $Response = New-Object System.Collections.ArrayList
    $DateInFuture = Read-Host "How long user will be active (: in Days) "
    ForEach ($GroupXc in $GroupC) {
        Add-ADGroupMember -Credential $cred -Identity $GroupXc -Members $User.samaccountname -Verbose
    }
}
我想用变量$DateInFuture groupXc凭据将结果保存在.csv中 我不确定如何在循环外提取GroupXc


任何简单的方法???

这里没有太多的上下文,但这应该让你开始。您需要用对象填充数组或arraylist。这使得导出到csv文件非常容易

例如:

    Switch -Wildcard ("$($group)$($action)") {
        "Citrix*" {$GroupC = ("#GG-$CC--Citrix1","#GG-$CC-Citrix2-","#GG-$CC-Citrix3")}
    }
    $OutputFile = C:\Temp\SomeOutput.csv # Obviously you should change this...
    $Response = New-Object System.Collections.ArrayList

    If ($group -eq "Citrix")
    {
        $DateInFuture = Read-Host "How long user will be active (: in Days) "

        ForEach ($GroupXc in $GroupC)
        { # Start loop
            $Response.Add( 
                [PSCustomObject]@{
                DateInFuture = $DateInFuture
                GroupXc      = $GroupXc
                Credentials  = $Credentials
            } ) 

        Add-ADGroupMember -Credential $cred -Identity $GroupXc -Members $User.samaccountname -Verbose
        } # End loop
    }

$Response | Export-Csv -Path $OutputFile -NoTypeInformation
显然,您必须考虑对象的填充方式和位置。你必须使它符合你的需要。这只是一个例子