Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

powershell script example

## Define the service name in a variable
$ServiceName = 'EventLog'

## Read the service from Windows to return a service object
$ServiceInfo = Get-Service -Name $ServiceName

## If the server is not running (ne)
if ($ServiceInfo.Status -ne 'Running') {
	## Write to the console that the service is not running
	Write-Host 'Service is not started, starting service'
	## Start the service
	Start-Service -Name $ServiceName
	## Update the $ServiceInfo object to reflect the new state
	$ServiceInfo.Refresh()
	## Write to the console the Status property which indicates the state of the service
	Write-Host $ServiceInfo.Status
} else { ## If the Status is anything but Running
	## Write to the console the service is already running
	Write-Host 'The service is already running.'
}
Comment

PREVIOUS NEXT
Code Example
Shell :: git assume undo unchanged 
Shell :: prettier npm 
Shell :: vi quit 
Shell :: linux mount sd card 
Shell :: adding this directory to path mac 
Shell :: sonarqube linux installation 
Shell :: cmd run exe as service 
Shell :: install docker desktop ubuntu 
Shell :: how to encrypt and decrypt a text file using openssl rsa public and private keys 
Shell :: git backtrack to commit 
Shell :: how to deploy react and backend to github pages 
Shell :: nvm fish shell 
Shell :: how to view the list of your environments in your terminal or Anaconda prompt 
Shell :: bash script assign array to variable 
Shell :: creat a new repository 
Shell :: install solidity compiler command with version 
Shell :: git clone password authentication failed 
Shell :: cut bash 
Shell :: how to update kali linux 2022 
Shell :: replace a newline using sed linux bash 
Shell :: kills a process on port 
Shell :: git add existing proj to a new repo failed 
Shell :: awk bash 
Shell :: zsh get first line 
Shell :: set up django-lint 
Shell :: extract zip in collab 
Shell :: time machine logs 
Shell :: git init set upstream 
Shell :: kali linux image 
Shell :: meld between two branches 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =