I am trying to write a simple script to check if a network drive is available, map it if it isn't, then double check the mapping worked (to report any issues like the account mapping it has accidentally expired etc). If it fails at the double check, it will send an email, otherwise it reports all ok.
I cannot get the double check to work. I think I have my statements wrong?
$Networkpath = "X:\Testfolder"
$pathExists = Test-Path -Path $Networkpath
If (-not ($pathExists)) {
(new-object -com WScript.Network).MapNetworkDrive("X:","\\Server-01\Share")
}
ELSEIF (-not ($pathExists)) {
Write-Host "Something went very wrong"
#Insert email code here
}
ELSE {Write-Host "Drive Exists already"}