Aguarde até que a máquina volte a ficar on-line e, finalmente, limpe usando Remove-PSSession
:
$Uri = Get-AzureWinRMUri -ServiceName $ServiceName -Name $VMName -Verbose
$PSSession = New-PSSession -ConnectionUri $Uri -Credential $Credential -Verbose
$PSDomainSessionCreate = { New-PSSession -ConnectionUri $Uri -Credential $DomainCredential -Verbose }
Invoke-Command -Session $PSSession -ScriptBlock { Add-Computer -DomainName $Using:DomainName -Credential $Using:DomainCredential -Restart -Passthru -Verbose }
# Wait for machine to restart
$PSDomainSession = &$PSDomainSessionCreate
# Use $PSDomainSession to configure the machine
# Then cleanup using the Remove-PSSession cmdlet as suggested by @Andy
Remove-PSSession -Session $PSSession,$PSDomainSession