Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: New-Object Saved as a $variable

$
0
0

Do you want this object to be in a variable in the remote session (inside the script block that's running with Invoke-Command), or back on your local computer? For the former, assign the result from Invoke-Command to a variable. For the latter, you can either assign the result of the "If" statement to a variable, or put variable assignments for both calls to New-Object:

$variable = Invoke-Command (etc)
 
# or
 
$variable =  if ($Result)
{
    New-Object (etc)
}
else
{
    New-Object (etc)
}
 
# or
 
if ($Result)
{
    $variable = New-Object (etc)
}
else
{
    $variable = New-Object (etc)
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles