如何从PowerShell返回PSObject []并从该PSObject获取价值

时间:2018-11-09 11:25:36

标签: powershell psobject

执行PowerShell脚本,并以PSObject[]的形式返回输出,但是无法从该对象获取值。

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
    Enable-PSRemoting -Force
    $Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $password
    $ADUserslist
    Invoke-Command -ComputerName $IP -ArgumentList (,$ADUserslist) -ScriptBlock {
        Param([PSCustomObject[]]$ADUsers)
        # Import active directory module for running AD cmdlets
        Import-Module ActiveDirectory 
        # Store the data from ADUsers.csv in the $ADUsers variable
        # Create an empty System.Array object   
        foreach ($User in $ADUsers) {
            $User.Status = "Success"
    }
    $ADUsers
} -Credential $Credentials

0 个答案:

没有答案