0

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
THARMA KS
  • 21
  • 1
  • 6
  • Your code is broken. What command starts this `} -Credential $Credentials` ? Also, what is the use of creating the `$employees` array if (at least so you say in the comments) the `$ADUsers` is already a parsed csv file? – Theo Nov 09 '18 at 12:47
  • Using } -Credential $Credentials Pass the credentials to take remote session to execute the script and $employees array is no need.I will pass $ADUserslist, $User, $password as input argument. – THARMA KS Nov 09 '18 at 14:45
  • I understand you need credentials, but still.. the code as it is now is broken. Remove the `}` above `$ADUsers` because this now closes the `Invoke-Command` – Theo Nov 09 '18 at 20:09
  • Yes, I understood the } was removed. – THARMA KS Nov 12 '18 at 07:12
  • now I can get the output data but the status column value haven't updated. – THARMA KS Nov 12 '18 at 07:18

0 Answers0