0
$username = "username" 
$password  = convertto-securestring "*****" -asplaintext -force 
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password  
$session = New-PSSession -computername 'testserver' -credential $cred 
Invoke-Command -Session $session -ScriptBlock {New-NetIPAddress -IPAddress 10.201.10.10 -InterfaceAlias 'LoadBalancer' -AddressFamily IPv4 -PrefixLength 24}
Remove-PSSession -Session $session

Above script runs fine from VMM server but it fails when I include it as a part of site recovery plan.

Error Message from Azure: Script exception: Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

Where am I going wrong?

2 Answers2

0

Not super great at scripting, but hopefully what I point out can help lead to the right answer.

$session = New-PSSession -computername 'testserver' -credential $cred -> Creates a session on the computer specified. $session -> Since that session is created I don't believe you need this. ... $session - Since the session is already running. I don't see the need to call the same one again. Remove-PSSession $session -> The variable your passing is to create yet another session. Not remove the existing. I think you need to just specify the servername here or the ID of the session on said server.

Mark
  • 179
  • 2
  • 13
  • Well, the extra $session before and after Invoke-Command is there because I wanted to see the details about the session that was created. It's simply there for debug purposes. – milan21984 Jun 19 '15 at 20:49
0

Figured out the solution for this issue. Even though the VMM successfully executed my script, Azure was showing an error. It was mainly complaining about the very last line in the script. Modified the last line with following and it works fine now.

Remove-PSSession -Session $session