troubleshooting Question

verify the presence of a service and if no, exit the script

Avatar of bibi92
bibi92Flag for France asked on
Powershell
2 Comments1 Solution430 ViewsLast Modified:
Hello,

How can I modifiy this script for verify the presence of a service and if no, exit the script
#Definition des variables
$fullPathIncFileName=$MyInvocation.MyCommand.path
$dir_name=Split-Path $MyInvocation.MyCommand.path
$array_str=$fullPathIncFileName.split(".")
[int] $nb_str=@($array_str).count
$_SNAPID=@($array_str)[$nb_str-2]
$SPOOL_FILE=$dir_name+"\t_schemas.log"
$SPOOL_FILE1=$dir_name+"\t_schemas.$_SNAPID"
$_HOST   = $env:computername
$ORACLE_HOME = gci HKLM:Software\Oracle\KEY*,HKLM:Software\Oracle\HOME* |select @{n="Oracle_Home"; e={$_.GetValue("Oracle_Home")}}
$_DBLIST = get-service -Name "OracleService*" | Where-Object {$_.status -eq "Running"} | ForEach {$_.name.Replace("OracleService","")}
$st=0
if($_DBLIST.count -eq 1) {
  echo "" 
exit 0
}
Thanks
bibi
ASKER CERTIFIED SOLUTION
Joe Klimis

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros