In my PowerShell code I am sending an email out if an unexpected folder is found in a certain directory when a command is executed. This works already, but I need to know is how to queue that email if the laptop is not connected to a network. Once the laptop has network connectivity then send the email out.
if ($item.Attributes -eq "Directory")
{
if ($ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1})
{
Send-MailMessage -SmtpServer $SmtpServer -From "$Admin" -To "$Admin" -Subject "Unexpected folder in $path folder on ""$env:computername""" -Body "There is an unexpected folder in the $path Folder on ""$env:computername"". Check on this ASAP."
continue
}
else
{
#Need to queue this message until we are connected to a network again
Send-MailMessage -SmtpServer $SmtpServer -From "$Admin" -To "$Admin" -Subject "Unexpected folder in $path folder on ""$env:computername""" -Body "There is an unexpected folder in the $path Folder on ""$env:computername"". Check on this ASAP."
continue
}
}
Thank you in advance