只有变量 运行 但变量没有 "catch" 的 powershell 脚本
powershell script with only variables running but the variable dont "catch"
我有一个 script1.ps1,里面有 scrip2.ps1,其中包含以下几行:
echo *****blabla*****
$hostName = "host1"
$statip = "192.168.3.1"
$subnet = "255.255.255.0"
$gateWay = "192.168.3.254"
在 script1.ps1 我 运行 是这样的:
cd /home/user/
& ./script2.ps1
当我 运行 它时,我在我的终端上看到 *****blabla*****。
但是当我尝试回显其余变量时 - 我什么也没得到。甚至不为空。
如果我复制命令并通过它们,它将起作用。
设法通过使用解决问题:
Get-Content '<fullpath>/script2.ps1' | Invoke-Expression
我有一个 script1.ps1,里面有 scrip2.ps1,其中包含以下几行:
echo *****blabla*****
$hostName = "host1"
$statip = "192.168.3.1"
$subnet = "255.255.255.0"
$gateWay = "192.168.3.254"
在 script1.ps1 我 运行 是这样的:
cd /home/user/
& ./script2.ps1
当我 运行 它时,我在我的终端上看到 *****blabla*****。
但是当我尝试回显其余变量时 - 我什么也没得到。甚至不为空。
如果我复制命令并通过它们,它将起作用。
设法通过使用解决问题:
Get-Content '<fullpath>/script2.ps1' | Invoke-Expression