Is there anything I can do to this code to optimize it to use less resources?
write-host (get-date -format s) " Beginning script..."
Add-Type -AssemblyName System.Windows.Forms
do{
$len = [System.Windows.Forms.Screen]::AllScreens.Length;
if($len-eq1){
$ie = Get-Process -Name iexplore -ErrorAction SilentlyContinue
if ($ie -ne $null){
Write-Host (get-date -format s) "Stopping IE..."
$ie | Stop-Process
}
}elseif($len-eq2){
$ie = Get-Process -Name iexplore -ErrorAction SilentlyContinue
if ($ie -eq $null){
write-Host (get-date -format s) " Starting IE..."
Start-Sleep -s 5 #5
$ie = Open-InternetExplorer -Url http://localhost/ -Left 1366 -FullScreen -InForeground #This is an external function that works well.
write-Host (get-date -format s) " IE Started"
}
}
start-sleep -s 10
}while(1-eq1)