-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoke-HostsFilesActions.ps1
32 lines (27 loc) · 1.22 KB
/
Invoke-HostsFilesActions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Requires:
# Log.psq
# Set-HostsEntry.sp1
$scriptPath = Split-Path -Parent $script:MyInvocation.MyCommand.Path
. $scriptPath\Set-HostsEntry.ps1
function Invoke-HostsFileActions([System.Xml.XmlElement]$Config, [string]$ProgressTitle) {
[System.Xml.XmlNodeList]$hostEntries = $Config.SelectNodes("./*")
[int]$hostEntryCount = $hostEntries.Count
[int]$hostEntryIndex = 0
# Report progress
Write-Progress -Activity $ProgressTitle -Status "Setting host file entries" -PercentComplete ($hostEntryIndex / $hostEntryCount * 100)
$hostEntries | ForEach-Object {
if ($_.LocalName -eq "Entry") {
try {
Set-HostsEntry -IPAddress $_.IPAddress -HostName $_.HostName
Log "Information" "$($_.HostName) ($($_.IPAddress)) host entry set successfully."
} catch [Exception] {
Log-Error $_.Exception "An exception has been thrown while wrting hosts file entry ($($_.HostName) -> $($_.IPAddress)). Please check the following logs for more details."
}
}
$hostEntryIndex++
# Report progress
Write-Progress -Activity $ProgressTitle -Status "Recycling $($_.AppPool)" -PercentComplete ($iisActionIndex / $hostEntryCount * 100)
}
# Report progress (completed)
Write-Progress -Activity $ProgressTitle -Status "Completed" -Completed
}