# code-block-pro/1.27.5/build/shiki/samples/powershell.sample

Code Block Pro – Beautiful Syntax Highlighting, version 1.27.5. 23 lines.

- Page: https://pluginprobe.com/plugins/code-block-pro/1.27.5/code/build/shiki/samples/powershell.sample
- Raw: https://pluginprobe.com/plugins/code-block-pro/1.27.5/raw/build/shiki/samples/powershell.sample
- Modified: 2023-09-03T01:04:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-block-pro/1.27.5/code/build/shiki/samples/powershell.sample#L10-L20`.

```
## 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.'
}

## From https://adamtheautomator.com/powershell-script-examples/

```
