Powershell Scriptblock Return Variable

[Solved] Powershell Scriptblock Return Variable | Powershell - Code Explorer | yomemimo.com
Question : powershell scriptblock return variable

Answered by : kevin-debono

$server1 = "dc-1"
$server2 = 'dc-2'
$server3 = 'app'
$computers = ( $server1, $server2, $server3 )
$result3 = Invoke-Command -Credential $domaincredentials -ComputerName $computers -ScriptBlock {
$SB = {
$objht = @{}
$objht.Testa = 'testa'
$objht.Testb = 'testb'
$objht.Testc = 'testc'
New-Object psobject -propertyh $sb
}
}
write-host $result3

Source : https://community.spiceworks.com/topic/1970857-export-a-variable-value-from-invoke-command-to-local | Last Update : Sun, 31 Jul 22

Answers related to powershell scriptblock return variable

Code Explorer Popular Question For Powershell