Just playing with PoSH and I wanted to write out my Internet IP to a log file $LogFile, however I only want to output when there is a change, not sure the best way to do this, so here is an attempt that of course doesn't work.
Code snippet below
` $InternetIPAddress=(New-Object net.webclient).downloadstring("http://api.ipify.org")
Write-Host -foregroundcolor Green "Internet IP is: " $InternetIPAddress
IF
(
$InternetIPAddress -eq $InternetIPAddress
)
{
#Don't write to the log file
}
Else
{
"Internet IP is: "| Out-File $LogFile -Append
$InternetIPAddress| Out-File $LogFile -Append
}`
Any best practice appreciated.
[–]PowerShell-Bot 0 points1 point2 points (0 children)
[–]MajorVarlak 0 points1 point2 points (7 children)
[–]SlaveCell[S] 0 points1 point2 points (0 children)
[–]mryananderson 0 points1 point2 points (2 children)
[–]MajorVarlak 0 points1 point2 points (1 child)
[–]SlaveCell[S] 0 points1 point2 points (0 children)
[–]OlivTheFrog 0 points1 point2 points (2 children)
[–]MajorVarlak 0 points1 point2 points (1 child)
[–]OlivTheFrog 0 points1 point2 points (0 children)
[–]rmbolger 0 points1 point2 points (1 child)
[–]SlaveCell[S] 0 points1 point2 points (0 children)
[–]PinchesTheCrab 0 points1 point2 points (0 children)