Preet Sangha
Preet Sangha

Reputation: 65496

Running a command in power shell profile script has different behaviour than command line

then I run cmd /c net use h: /d from the powershell command line it all succeeds

but when I run the same command in the powershell $profile script it asks for a manual confirmation.

alt text

Anyone know how to prevent the confirmation please?

Upvotes: 1

Views: 4314

Answers (2)

Josh
Josh

Reputation: 31

(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:", 1, 1)

The second 1 at the end I believe is for bUpdateProfile. The drive would not disappear from the Explorer window unless that value was there.

Upvotes: 0

Preet Sangha
Preet Sangha

Reputation: 65496

I cannot find a way to force the net program to force the drive deletion, however I can use the following powershell script to control the Windows Script Host to

map a drive:

(New-Object -ComObject WScript.Network).MapNetworkDrive("H:", '\\SVNAS301\blah')

remove a mapping

(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:")

Or remove a mapping with force

(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:", 1)

Upvotes: 3

Related Questions