Have a Question?
< All Topics
Print

PS | Functions

Update Host file with PowerShell

Function Update-HostFile {
    #Host = "192.168.1.200 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}
     }

#Output    
$HostName = "52.255.54.85 yongkw.com"
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
}
Table of Contents
Scroll to Top