Is there a way to make a script jump to a specific spot like :GOTO in command prompt? I wanted to make the script jump to the beginning when it is ended.
$tag1 =
Here's and example using your script:
$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
Use . instead of & inside the script block to prevent it from walking up the call stack.
Putting code into script blocks to be called later from arbitrary points in the script (emulating a GoTo) is functionally the same as using a function, and script block used in this manner are sometimes referred to as "anonymous functions".