Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Check if drive exists, If not map

$
0
0

I want to check for the existance of a drive mapping (called X in this example) and if it does not exist, I want to map it. Here is what I have so far:

$driveCheck = Get-PSDrive | Where-Object { $_.Name -match "X" } | Select-Object name

# This provides the following output:

# Name
# ----
# X

$map = new-object -ComObject WScript.Network
$map.MapNetworkDrive("X:", "\\Server\Share", $true, "Domain\user", "password")


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>