views:

55

answers:

1

I am trying to optimise a login script to make it as robust and quick to execute as possible.

The script logs a number of drives, and I can see I can use either:

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

or

net use x: \\myserver\myshare

To map the drives.

Which is the "better" way? The "traditional" way seems more robust, but is slower than the newer method.

I'm also getting some oddities when I test to see if the drives exist. Even though they show in Explorer, sometimes when I test with:

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

it does not output any result. This seems to only happen some of the time, but I haven't worked out the pattern.

Thanks,

Ben

+2  A: 

Mapping a drive with "net use" does not automatically make it visible in powershell as a PSDrive. They are not the same thing unfortunately. Test-Path checks only a PSPath, which is either a UNC path or a PSDrive (or provider-qualified like filesystem::c:) pointing at a powershell provider.

This is one in a long line of reasons why powershell is not the best shell for login scripts.

-Oisin

x0n