网络共享脚本 - 自动检查驱动器号和路径

network share script - auto check drive letter and path

我有这个基于用户名添加路径的脚本:

$credential = Get-Credential
$user=$credential.GetNetworkCredential().UserName
New-PSDrive -Name x -PSProvider FileSystem -Root "\192.168.1.1$($user)" -Credential $credential -persist

我正在努力使它更健壮,我如何编辑它以检查哪个驱动器号可用以及网络路径是否已与现有驱动器号映射,所以如果结束就不会出错用户多次运行它。

可用盘符:

ls function:[d-z]: -n | ?{ !(test-path $_) }

归功于