Set-TimeZoneID.ps1


Description

Purpose

A brief description of the Set-TimeZoneID function.

Detailed Description

A detailed description of the Set-TimeZoneID function.

Back to Top

Usage

Example 1

PS C:\> Set-TimeZoneID -ComputerName 'value1'

Back to Top

Notes

Additional information about the function.

Back to Top


Script

function Set-TimeZoneID {
	<#
	.SYNOPSIS
		A brief description of the Set-TimeZoneID function.
	
	.DESCRIPTION
		A detailed description of the Set-TimeZoneID function.
	
	.PARAMETER ComputerName
		A description of the ComputerName parameter.
	
	.EXAMPLE
		PS C:\> Set-TimeZoneID -ComputerName 'value1'
	
	.OUTPUTS
		System.String
	
	.NOTES
		Additional information about the function.
#>
	[CmdletBinding(DefaultParameterSetName = 'Default',
		supportsShouldProcess = $true,
		HelpUri = 'https://github.com/BanterBoy'
	)]
	[OutputType([string])]
	param
	(
		[Parameter(ParameterSetName = 'Default',
			Mandatory = $false,
			ValueFromPipeline = $true,
			ValueFromPipelineByPropertyName = $true,
			HelpMessage = 'Enter computer name or pipe input'
		)]
		[Alias('cn')]
		[string[]]$ComputerName = $env:COMPUTERNAME,
		[Parameter(ParameterSetName = 'Default',
			Mandatory = $false,
			ValueFromPipeline = $true,
			ValueFromPipelineByPropertyName = $true,
			HelpMessage = 'Enter computer name or pipe input'
		)]
		[Alias('cred')]
		[ValidateNotNull()]
		[System.Management.Automation.PSCredential]
		[System.Management.Automation.Credential()]
		$Credential,
		[Parameter(ParameterSetName = 'Default',
			Mandatory = $false,
			ValueFromPipeline = $true,
			ValueFromPipelineByPropertyName = $true,
			HelpMessage = 'Enter computer name or pipe input'
		)]
		[Alias('tz')]
		[ArgumentCompleter( {
				$Zones = Get-TimeZone -ListAvailable | Select-Object -Property Id
				foreach ($Zone in $Zones) {
					$Zone.Id
				}
			}) ]
		[string]$TimeZone = "GMT Standard Time"
	)
	BEGIN {
	}
	PROCESS {
		if ($PSCmdlet.ShouldProcess("$Computer to $TimeZone", "Setting Time Zone information...")) {
			if ($credential) {
				foreach ($Computer in $ComputerName) {
					Invoke-Command -ComputerName $Computer -ScriptBlock -Credential $Credential {
						Set-TimeZone -Id $TimeZone
					}
				}
			}
			else {
				foreach ($Computer in $ComputerName) {
					Invoke-Command -ComputerName $Computer -ScriptBlock {
						Set-TimeZone -Id $TimeZone
					}
				}
			}
		}
	}
	END {
	}
}

Back to Top

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.

Issue


Back to Top