I am looking for some assistance, or at least a point in the right direction. Still a bit new with PS scripting.
I have a PS script to pull the LastBootUpTime from a remote host. I have a batch file first setting the execution policy to bypass to allow the script to run. The actual PS script then runs with elevated privileges, and prompts to enter the target computer name. The script runs successfully and the LastBootUpTime is displayed when the script exits. However if I try to modify the script to restart the function by using a do while, or starting a loop and then using an if statement, I find the output of the get-WmiObject is not displayed. It seems as though the data obtained from get-WmiObject is held until the script exits. Once the script exits, the data is then displayed.
Is there a better way to retrieve the lastBootUpTime, and have it displayed on screen without the script completely exiting?
Many Thanks in advance.
function GetStartDate { $computername = read-host "Enter the computer name " get-WmiObject Win32_OperatingSystem -computername $computername |select CSname,@{label='lastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} set-executionpolicy -scope process restricted }