- function Connect_RemoteMachine ($username,$pwd,$ip_remote)
- {
- $pwd=ConvertTo-SecureString $pwd -AsPlainText -Force
- $cred=New-Object System.Management.Automation.PSCredential($username,$pwd)
-
-
- $s=new-PSSession -ComputerName $ip_remote -Credential $cred
- if($s -gt $null)
- {
- return $s
- }
- }
-
-
- function reset-comupter
- {
-
-
- $a=1
- $session = Connect_RemoteMachine "administrator" "11111111" localhost
- Invoke-Command -Session $session -ScriptBlock {
-
-
- $b=2
- $c=$a+$b
- Write-Output $c
-
-
- }-ArgumentList $a,$b,$c
- Remove-PSSession $session;
-
- }
- reset-comupter
复制代码 在以上代码中,$a无法在新的session中被调用,如果我想在新session中调用之前定义好的变量,应该怎么做呢? |