Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Need help with a broken ForEach

$
0
0

I am attempting to write a script that takes a list of IP address’s, finds alive hosts, then checks to make sure that a specific service is installed. If the service is NOT installed it should be adding the IP address to the $notinstalled array. This is not working as I thought it should.

Could someone tell me what I am doing wrong in that specific ForEach section? This script is a learning / work in progress as I have never written a powershell script before.

I have attached the entire script, such as it is.

Thanks.

Try
{
ForEach ($entry in $alivehosts){
	$svc = Get-Service -Display $sname -ComputerName $entry -ErrorAction SilentlyContinue
	IF( -not $sname) {$notinstalled += $entry}
	else { $sname + " is installed on " + $entry}
	}

Viewing all articles
Browse latest Browse all 13067

Trending Articles