< Back

Set-HFMHostsFileEntry

Tue Jan 14, 2020 1:39 am

NAME Set-HFMHostsFileEntry



SYNOPSIS

Add new entry/entries to hosts file.





SYNTAX

Set-HFMHostsFileEntry [-Path] <HostsFile[]> [-Entries] <HostsEntry[]> [<CommonParameters>]





DESCRIPTION

Add new entry/entries to hosts file(s)





PARAMETERS

-Path <HostsFile[]>



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-Entries <HostsEntry[]>



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

You must provide a valid path of type [HostsFile] and an entry of type [HostsEntry]





OUTPUTS







NOTES





This cmdlet uses Class.HostsManagement classes, by @StephaneVG

Fork hist project if you like it: https://github.com/Stephanevg/Class.HostsManagement

Visit his site, and read his article a boute pratical use of PowerShell Classes:

http://powershelldistrict.com/powershell-class/



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$Host = Get-HFMHostsfile



PS C:\\> $Comment1 = New-HFMHostsFileEntry -IpAddress "20.0.0.0" -HostName "toto" -FullyQualifiedName "toto.com"

-Description "ahahha" -EntryType Comment

PS C:\\> $Comment2 = New-HFMHostsFileEntry -IpAddress "21.0.0.0" -HostName "toto" -FullyQualifiedName "toto.com"

-Description "ahahha" -EntryType Comment

PS C:\\> Set-HFMHostsFileEntry -Path $Host -Entries $Comment1,$Comment2



Create 2 new [HostsEntry], and add them to the local hosts file.

A backup is automatically created.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$Comment1 = New-HFMHostsFileEntry -IpAddress "20.0.0.0" -HostName "toto" -FullyQualifiedName "toto.com"

-Description "ahahha" -EntryType Comment



PS C:\\> "Computer1","Computer2" | Get-HFMHostsfile | Set-HFMHostsFileEntry -Entries $Comment1



Create a new [HostsEntry], and add it to hostsfile on computer1, and computer2











RELATED LINKS