Stuck in while loop

I have a small script that checks the communication date of the mcafee agent.

$GetLastCommunication = & "C:\Program Files\McAfee\Agent\cmdagent" -i | Select-String -Pattern LastASCTIME | Out-String
$GetLastCommunication = $GetLastCommunication.Replace("`n", "").Replace("`r", "").Replace(" ","")

Start-Job -ScriptBlock {
	$newagentdir = (Get-ChildItem -Recurse "\\IP\Downloads\" -Include "FramePkg.exe").FullName
	$arg = "/forceinstall /install=agent /silent"
	Copy-Item -Path $newagentdir -Destination $env:TEMP
	Start-Process -Wait $env:TEMP\FramePkg.exe -ArgumentList $arg
}

while ($GetLastCommunication = "LastASCTime:N/A"){
	sleep -Seconds 5
}

Reload-Form

after the installation, the LastASCTime line changes from N/A to the time of communication.
I need for him to check when the variable changes and then reloads the form when there’s communication.
Currently, is getting stuck in the while loop and doesn’t reload the form.

Any ideas why?

Thanks

d3kk3r,
Welcome to the forum. :wave:t4:

Yes.
The equal sign “=” is the assignment operator - not the comparison operator for equality. :point_up_2:t4: … and since the assignment

$GetLastCommunication = "LastASCTime:N/A"

always works your loop will run for ever. :wink:

But even if you change the operator to the correct “-eq” - as long as you set the variable you’re using to check in your loop condion outside of your loop the comparison will always stay the same. You have to move the variable assignment for $GetLastCommunication inside your loop script block.

1 Like

That was it :slight_smile:

Changed the operator to -eq and moved the variable inside the while loop.

Worked great!

Thanks!