[.net] Why "net use * /delete" does not work but waits for confirmation in my PowerShell script?

I have a script where I want to disconnect from the mapped drives before I create a new PSDrive.

Otherwise I get this error:

New-PSDrive : Multiple connections to a server or shared resource by the same user , using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again

So I have this line:

net use * /delete

(Unfortunately I could not find a way to disconnect from a specific mapped drive just by providing the server name so far :( )

When PS comes to this line

You have these remote connections:

\\ServerName\SharedFolder Continuing will cancel the connections.

And then it stops executing.

Is there a way to auto confirm disconnecting from the mapped drives automatically without confirmation (it does not have to be the net use /delete solution)?

Note that: I run my script from the Powershell ISE PS promt

This question is related to .net powershell mapped-drive net-use

The answer is


With PowerShell 5.1 in Windows 10 you can use:

Get-SmbMapping | Remove-SmbMapping -Confirm:$false

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to powershell

Why powershell does not run Angular commands? How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line? How to print environment variables to the console in PowerShell? Check if a string is not NULL or EMPTY The term 'ng' is not recognized as the name of a cmdlet VSCode Change Default Terminal 'Connect-MsolService' is not recognized as the name of a cmdlet Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet Change directory in PowerShell

Examples related to mapped-drive

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed Find UNC path of a network drive? Why "net use * /delete" does not work but waits for confirmation in my PowerShell script? Map a network drive to be used by a service

Examples related to net-use

Why "net use * /delete" does not work but waits for confirmation in my PowerShell script?