PS | Functions

You are here:
← All Topics

Update Host file with PowerShell

Function Update-HostFile {
    #Host = " LAB-AD01"
    param ($HostName)
    If ((Get-Content "$($env:windir)\system32\Drivers\etc\hosts" ) -notcontains $HostName)   
     {Add-Content -Encoding UTF8  "$($env:windir)\system32\Drivers\etc\hosts" $HostName}

$HostName = ""
Update-HostFile $HostName

Convert UTC to Local Time

#Convert UTC to Local Time
Function Get-LocalTime($UTCTime)
$LocalTZ = (Get-TimeZone).ID
$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($LocalTZ)
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)

Write-Host "UTC Time:" $UTCTime
Write-Host "Local Time:" $LocalTime

#Return $LocalTime

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top