Get-W32TimeServiceStatus.ps1
19 Sep 2025Description
Purpose
Retrieves the status of the W32Time service on a specified computer.
Detailed Description
The Get-W32TimeServiceStatus function retrieves the status of the W32Time service on a specified computer. It uses the Get-Service cmdlet to get the service information and returns an object with the computer name, service name, and service status.
Usage
Example 1
Get-W32TimeServiceStatus -ComputerName "Server01"
Retrieves the status of the W32Time service on the computer named “Server01”.
Notes
This function requires administrative privileges to retrieve the service status on remote computers.
Script
<#
.SYNOPSIS
Retrieves the status of the W32Time service on a specified computer.
.DESCRIPTION
The Get-W32TimeServiceStatus function retrieves the status of the W32Time service on a specified computer. It uses the Get-Service cmdlet to get the service information and returns an object with the computer name, service name, and service status.
.PARAMETER ComputerName
Specifies the name of the computer to retrieve the W32Time service status from. If not specified, the local computer name is used.
.EXAMPLE
Get-W32TimeServiceStatus -ComputerName "Server01"
Retrieves the status of the W32Time service on the computer named "Server01".
.INPUTS
None. You cannot pipe input to this function.
.OUTPUTS
System.Management.Automation.PSObject. The function returns an object with the following properties:
- ComputerName: The name of the computer.
- ServiceName: The name of the W32Time service.
- ServiceStatus: The status of the W32Time service.
.NOTES
This function requires administrative privileges to retrieve the service status on remote computers.
.LINK
Get-Service
#>
function Get-W32TimeServiceStatus {
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$ComputerName = $env:COMPUTERNAME
)
try {
$service = Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-Service -Name "w32time" }
} catch {
Write-Error "Failed to get service status: $_"
return
}
$outputObject = New-Object PSObject
$outputObject | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName
$outputObject | Add-Member -NotePropertyName "ServiceName" -NotePropertyValue $service.Name
$outputObject | Add-Member -NotePropertyName "ServiceStatus" -NotePropertyValue $service.Status
return $outputObject
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.