Contents

PS | Functions

You are here:
← All Topics

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
}

Top Posts & Pages

Leave a Reply

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

Scroll to Top