How to return PSObject[] from PowerShell and get value from that PSObject

692 Views Asked by At

Execute the PowerShell script and return the output as PSObject[], but unable to get the values from that object.

    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

There are 0 best solutions below