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 =
Another variation on the script with some ideas taken from @mjolinor. I also switched away from using systeminfo
because at least on my computer, it's much slower than using the applicable WMI query.
while (1) {
$tag1 = Read-Host 'Enter tag # or Q to quit'
if ($tag1 -eq "Q") {
break;
}
sc.exe \\$tag1 start RemoteRegistry;
start-sleep -seconds 2
$OSInfo = get-wmiobject -class win32_operatingsystem -computername $tag1;
$OSInfo | Format-Table -Property @{Name="OS Name";Expression={$_.Caption}},@{Name="System Boot Time";Expression={$_.ConvertToDateTime($_.LastBootUpTime)}},@{Name="System Uptime (Days)";Expression={[math]::Round((New-TimeSpan -Start $_.converttodatetime($_.LastBootUpTime)|select-object -expandproperty totaldays),2)}} -AutoSize;
Get-EventLog system -computername $tag1 -InstanceId 2147489657 -Newest 10 | format-table EventID,TimeWritten,MachineName -AutoSize
}
I'm not certain that WMI needs remote registry, so you might be able to eliminate the sc.exe
line and sleep
altogether. Unless you need it for something else.