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