Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Problem forking a loop

$
0
0
Hi all, I wrote a script to do a one-off check against a remote machine if a specific kb is installed. I want it to loop if response to a read-host is either y or s. choosing "y" works as expected but if I choose s i run into an issue with it returning to the beginning but falling outside the loop. Below is my code. If you read through it, you will see what i'm trying to do. I commented out the actions if "s" is selected because i'm thinking i'm constructing my functions/loop wrong or missing something. Any suggestions would be appreciated. Thanks.
# This script will check if a particular hotfix is installed on the remote system.
# Usage: checkhotfix.ps1

cls
Write-Host"~~~~~~~~ Remote Hotfix Check ~~~~~~~"-foregroundcolor Cyan
#Function to obtain computername and check if host is online
Function KBCHECK
{
$objCom=Read-Host'Enter the remote computer name'
If (test-connection-computername$objCom-Quiet)
{
SAMECHECK
}
Else{
Write-Host$objCom"is Offline"-foregroundcolor Red
}
}
#Function to do the actual checking of the KB. When prompted for hotfix, enter only the KB number without the "KB"
Function SAMECHECK
{
$KB=Read-Host'Enter the KB to check. Enter just the number without the "KB"'
$KB="KB"+$KB
Write-Host"Thank you. Checking if patch is installed..."-foregroundcolor Cyan
If ($Patch=Get-Hotfix-computername$objCom | Select HotfixID,Description,InstalledOn | sort InstalledOn | ?{$_.HotfixID-eq$KB})
{
Write-Host"Patch is installed"-ForegroundColor Green
$Patch
Write-Host"Done."-ForegroundColor Cyan
}
Else{
Write-Host"This patch KB"$KB" is not installed on the remote machine or is not applicable"-ForegroundColor Red
}
}
# Loop while responding yes or same
Do
{
KBCHECK
$response=Read-Host"Check another computer? Enter ,, or for the same computer"
}
while ($response-eq"y")
######ElseIf ($response -eq "s")
######{
######}
EXIT

Viewing all articles
Browse latest Browse all 6937

Trending Articles