Octopus.Script exported 2021-08-04 by bilalmajali belongs to ‘Other’ category.
Remove given IP/host name entry exists in the hosts file.
This might be helpful in uninstall process.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
IP Address
IP =
The IP address which the host name should resolve to, e.g. 127.0.0.1
Script body
Steps based on this template will execute the following PowerShell script.
$ip = $OctopusParameters['IP']
$hostName = $OctopusParameters['HostName']
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$hosts = Get-Content $hostsPath
$match = $hosts -match ("^\s*$ip\s+$hostName" -replace '\.', '\.')
$hostsEntry = "$ip`t$hostName"
If ($match) {
write-host $hostsPath $hostsEntry " exist, then it will be removed."
}
else
{
write-host $hostsPath $hostsEntry "not exist"
Exit
}
(Get-Content -Path $hostsPath) |
ForEach-Object {$_ -Replace "$hostsEntry"} |
Set-Content -Path $hostsPath -Verbose
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "cf18f938-a052-4e0a-9549-85bfa9d95a2a",
"Name": "Windows - Remove Hosts File Entry",
"Description": "Remove given IP/host name entry exists in the hosts file.\n\nThis might be helpful in uninstall process.",
"Version": 1,
"ExportedAt": "2021-08-04T20:32:55.063Z",
"ActionType": "Octopus.Script",
"Author": "bilalmajali",
"Packages": [],
"Parameters": [
{
"Id": "d9320ac1-f7cd-4895-9a9b-b2a35bc9bbe3",
"Name": "IP",
"Label": "IP Address",
"HelpText": "The IP address which the host name should resolve to, e.g. 127.0.0.1",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "129047cb-3e0c-4d83-a734-7d9bef6b5023",
"Name": "HostName",
"Label": "Host Name",
"HelpText": "The host name which should resolve to the given IP, e.g. www.mydomain.com",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "$ip = $OctopusParameters['IP']\n$hostName = $OctopusParameters['HostName']\n\n$hostsPath = \"$env:windir\\System32\\drivers\\etc\\hosts\"\n$hosts = Get-Content $hostsPath\n$match = $hosts -match (\"^\\s*$ip\\s+$hostName\" -replace '\\.', '\\.')\n$hostsEntry = \"$ip`t$hostName\"\n\nIf ($match) {\nwrite-host $hostsPath $hostsEntry \" exist, then it will be removed.\"\n}\nelse\n{\nwrite-host $hostsPath $hostsEntry \"not exist\"\nExit\n}\n\n(Get-Content -Path $hostsPath) |\n ForEach-Object {$_ -Replace \"$hostsEntry\"} |\n Set-Content -Path $hostsPath -Verbose",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline"
},
"Category": "Other",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/Remove-Hosts-File-Entry.json",
"Website": "/step-templates/cf18f938-a052-4e0a-9549-85bfa9d95a2a",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAET9JREFUeNrsnV2MG1cVx2fGH2t7vU6zm27TTdxNgCTbVkUKggBFDR9FIKoWVX2o1BeeqNQXHnjgueozD7z2CSQEQgKEqlIVgSjQlrYQWoHaom6a0u7GyWbrxrus159je8zfvonZ2p7xx5w7c2d8/opWG9vruXPu755z7sfcq7fbbY3FopbOYLEYLBaDxWKw2AosBovFYLEYLBaLwWIxWCwGi8VisFgMFovBYrEYLBaDxWKwWCwGi8VgsRgsFovBki7Yx7KsvhcNw9B1nY3DYI1Qq9WyuhIYDYXJTgKy3k8oEomwSWcULJDUbDatmyL/fuOmotHobHI2Q2AJmARPHl9aEDZTkIUcLNwdSBJIqXCnCJcCL/wMd5YWWrCEc2o0GsqWMBaLCTfGYAVACHONroJyX/Bbsa4QLhksRVMo0zThpQJafriueDwemiQsDGAJFwWw5F2iWCwWCgURW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