What is the “best” way to display drives in Powershell?

I am trying to optimize the login script to make it as reliable and fast as possible.

The script registers multiple disks, and I see that I can use either:

(New-Object -ComObject WScript.Network).MapNetworkDrive("X:", \\myserver\myshare))

or

net use x: \\myserver\myshare

To map drives.

Which one is the "best" way? The "traditional" method seems more reliable, but slower than the new method.

I also get some weird things when I check if disks exist. Even if they appear in Explorer, sometimes when I test:

if (test-path x:) { write "Drive mapped already" }

it does not display any result. This seems to be happening only for a while, but I have not developed a template.

Thank,

Ben

+3
source share
1 answer

" " PowerShell PSDrive. , . Test-Path PSPath, UNC-, PSDrive ( :: c:), powershell.

, powershell .

-Oisin

+4

Source: https://habr.com/ru/post/1754624/


All Articles