Custom function to check if a service exist
hi
i wrote custom function check if service exists, make return true or false, return value si passed onto variable work with.
function isserviceexist { param ([string] $remotehost , [string] $servicename) write-output "remotehost=$remotehost, servicename=$servicename" $s=$null $s=get-wmiobject win32_service -computername $remotehost | {($_.name -like $servicename)}| select state #write-host "value of s $s" if ($s -eq $null) { write-host "returning false" $status = $false return $false } else { write-host "returning true" #return $true $status = $true return $true } }
the problem return value entire string.
running
$s = false; $s = (isserviceexist "servername" "servicename") write-host "status of install $s"returns strong of parameters passed function , boolean of true or false, need return true or false. think doing wrong.
too code:
(get-wmiobject win32_service -computername$remotehost -filter "name like '%$servicename%'").state -eq 'running'
that returns true or false , returns 1 object - not every object on computer.
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment