$Networkpath = "X:\Testfolder" $pathExists = Test-Path -Path $Networkpath If ($pathExists) { Write-host "Path already existed" Return #end the function if path was already there } else { (new-object -com WScript.Network).MapNetworkDrive("X:","\\Server-01\Share") } #Path wasn't there, so we created it, now testing that it worked $pathExists = Test-Path -Path $Networkpath If (-not ($pathExists)) { Write-Host "We tried to create the path but it still isn't there" #Insert email code here } ELSE {Write-Host "Path created successfully"}