执行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