Question : Powershell - determine if service exists on remote computer

The attached code checks the status of a service on remote computers to determine if the service exists or not.  For output I get
Installed - for computers that have IISAdmin
not installed - for computers that do not have IISAdmin
not installed - for computers that can not be accessed

The last group I would like to change.  How can it have powershell scripts determine if the service module is even accessible?  I do not want a 'not installed' if the system can not be checked.

Thanks in advance...again.

C
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
$colComputers = get-content "c:\powershell\outputfiles\AccessPass.Txt"
foreach ($strComputer in $colComputers)
    {
     
     $iisAdminSVC = [System.ServiceProcess.ServiceController]::GetServices($strComputer) | where{$_.name -eq 'IISADMIN'}
     switch ($iisAdminSVC.status)
        {     
        "Running" {$InstallStatus = "Installed"}
        "Stopped" {$InstallStatus = "Installed"}
        "Paused" {$InstallStatus = "Installed"}
        "Starting" {$InstallStatus = "Installed"}
        "Stopping" {$InstallStatus = "Installed"}
        "" {$InstallStatus = "NOT Installed"}
        }   
     write-host $strComputer $InstallStatus
    }

Answer : Powershell - determine if service exists on remote computer

I would do this. (there is a bug with get-service, that would be the most elegant, but remotely it does not handle silentlycontinue)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
$colComputers = get-content "c:\powershell\outputfiles\AccessPass.Txt"  
foreach ($strComputer in $colComputers)  
    {  
     $IISAdminSVC = Get-WmiObject -Class win32_service -Filter "name = 'IISAdminSVC'" -ErrorAction SilentlyContinue
     if($?) { 
	 	if($iisAdminSVC) {$InstallStatus = "Installed"}
		else{$InstallStatus = "NOT Installed"}
	}
	 else {$InstallStatus = "Inacccessible"}
     write-host $strComputer $InstallStatus  
    }
Random Solutions  
 
programming4us programming4us