bibi92
asked on
verify the presence of a service and if no, exit the script
Hello,
How can I modifiy this script for verify the presence of a service and if no, exit the script
#Definition des variables
$fullPathIncFileName=$MyIn vocation.M yCommand.p ath
$dir_name=Split-Path $MyInvocation.MyCommand.pa th
$array_str=$fullPathIncFil eName.spli t(".")
[int] $nb_str=@($array_str).coun t
$_SNAPID=@($array_str)[$nb _str-2]
$SPOOL_FILE=$dir_name+"\t_ schemas.lo g"
$SPOOL_FILE1=$dir_name+"\t _schemas.$ _SNAPID"
$_HOST = $env:computername
$ORACLE_HOME = gci HKLM:Software\Oracle\KEY*, HKLM:Softw are\Oracle \HOME* |select @{n="Oracle_Home"; e={$_.GetValue("Oracle_Hom e")}}
$_DBLIST = get-service -Name "OracleService*" | Where-Object {$_.status -eq "Running"} | ForEach {$_.name.Replace("OracleSe rvice","") }
$st=0
if($_DBLIST.count -eq 1) {
echo ""
exit 0
}
Thanks
bibi
How can I modifiy this script for verify the presence of a service and if no, exit the script
#Definition des variables
$fullPathIncFileName=$MyIn
$dir_name=Split-Path $MyInvocation.MyCommand.pa
$array_str=$fullPathIncFil
[int] $nb_str=@($array_str).coun
$_SNAPID=@($array_str)[$nb
$SPOOL_FILE=$dir_name+"\t_
$SPOOL_FILE1=$dir_name+"\t
$_HOST = $env:computername
$ORACLE_HOME = gci HKLM:Software\Oracle\KEY*,
$_DBLIST = get-service -Name "OracleService*" | Where-Object {$_.status -eq "Running"} | ForEach {$_.name.Replace("OracleSe
$st=0
if($_DBLIST.count -eq 1) {
echo ""
exit 0
}
Thanks
bibi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could include the following test to see if the service exists
$services = get-service
if ( (($services | where-object {$_.servicename -like "OracleService"}) | measure).count -ne $null) { "service found"}
I hope this helps
Joe