Server Uptime and Service Status matching the text command

Some important command to get server uptime and Service status matching the text.

To get server Uptime

================

 Invoke-Command -ScriptBlock {

$dt = Get-Date 

$tz = [System.TimeZone]::CurrentTimeZone

Write-Host "`r`nHostname:" $(hostname)

Write-Host "Timezone:"  $tz.StandardName " / " $tz.DaylightName

Write-Host "Date: " $dt

}

============================
Expected output





===================================================
Get Service status matching the text
===============================

Get-Service | Where-Object {$_.Name -Match "windows" -or $_.DisplayName -Match "window" }

Expected Output


Start a service

Start-Service -Name "ServiceName"

Stop a service

Stop-Service -Name "ServiceName"


PS C:\Windows\system32> get-service -name wuauserv

Status   Name               DisplayName
------   ----               -----------
Stopped  wuauserv           Windows Update


PS C:\Windows\system32> start-service wuauserv
PS C:\Windows\system32> get-service -name wuauserv

Status   Name               DisplayName
------   ----               -----------
Running  wuauserv           Windows Update


PS C:\Windows\system32> stop-service wuauserv
PS C:\Windows\system32> get-service -name wuauserv

Status   Name               DisplayName
------   ----               -----------
Stopped  wuauserv           Windows Update



No comments:

Post a Comment

Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is 10.0.0.1/2 You need to connect your laptop and storage with...