Skip to content
This repository was archived by the owner on May 30, 2019. It is now read-only.

Commit 87e3d0a

Browse files
committed
VariableIsUndefined error when not renaming host
VariableIsUndefined error when not renaming host thanks to PowerShell strict mode. Resolved by using boolean to check if rename operation needs to be performed.
1 parent 310aeff commit 87e3d0a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Functions/ConvertTo-GraphiteMetric.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Function ConvertTo-GraphiteMetric
5656
[System.Collections.Specialized.OrderedDictionary]$MetricReplacementHash
5757
)
5858

59+
# Setup booleen for if we are changing hostname
60+
$renameHost = $false
61+
5962
# If HostName is being overwritten
6063
if ($HostName -ne $env:COMPUTERNAME)
6164
{
@@ -64,6 +67,9 @@ Function ConvertTo-GraphiteMetric
6467

6568
# Set the host name to the hostGuid
6669
$MetricToClean = $MetricToClean -replace "\\\\$($env:COMPUTERNAME)\\","\\$($hostGuid)\"
70+
71+
$renameHost = $true
72+
6773
}
6874

6975
if ($MetricReplacementHash -ne $null)
@@ -152,11 +158,12 @@ Function ConvertTo-GraphiteMetric
152158
}
153159

154160
# If $hostGuid has been generated, replace the guid inside the metrics with the correct HostName
155-
if ($hostGuid)
161+
if ($renameHost)
156162
{
157163
Write-Verbose "Replacing hostGuid '$($hostGuid)' with requested Hostname '$($HostName)'"
158164
$cleanNameOfSample = $cleanNameOfSample -replace $hostGuid,$HostName
159165
}
160166

167+
161168
Write-Output $cleanNameOfSample
162169
}

0 commit comments

Comments
 (0)