有没有办法让脚本跳转到命令提示符中的特定位置,例如:GOTO?我想让脚本结束时跳到开头。
$tag1 = Read-Host 'Enter tag #'
cls
sc.exe \\$tag1 start RemoteRegistry
cls
Start-Sleep -s 2
cls
systeminfo /S $tag1 | findstr /B /C:"OS Name" /C:"System Boot Time" /C:"System Up Time";
Get-EventLog system -computername $tag1 -InstanceId 2147489657 -Newest 10 | ft EventID,TimeWritten,MachineName -AutoSize
Pause
这是使用您的脚本的示例:
$GetInfo = {
$tag1 = Read-Host 'Enter tag # or Q to quit'
if ($tag1 -eq 'Q'){Return}
cls
sc.exe \\$tag1 start RemoteRegistry
cls
Start-Sleep -s 2
cls
systeminfo /S $tag1 | findstr /B /C:"OS Name" /C:"System Boot Time" /C:"System Up Time"
Get-EventLog system -computername $tag1 -InstanceId 2147489657 -Newest 10 |
ft EventID,TimeWritten,MachineName -AutoSize
.$GetInfo
}
&$GetInfo
使用 。而不是脚本块内的 & ,以防止它沿着调用堆栈向上移动。
将代码放入脚本块中以便稍后从脚本中的任意点调用(模拟 GoTo)在功能上与使用函数相同,以这种方式使用的脚本块有时称为“匿名函数”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)