Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell equivalent of Batch command "START" to open a window with a mapped drive

Tags:

powershell

This is the batch commands I use to open a window with a mapped drive:

net use X: "\\SERVERNAME\FOLDER" /user:"USER" "PASSWORD"
START X:\

What is the PowerShell version of this?

like image 730
George Dudnikov Avatar asked Oct 27 '25 10:10

George Dudnikov


1 Answers

Both of your commands work as-is in PowerShell:

  • net refers to the net.exe external program (a standard Windows utility), which PowerShell can equally call.

    • On Windows 8 / Windows Server 2012 or higher, you can use the New-SmbMapping cmdlet as an alternative to net use.

    • Note that while PowerShell cmdlets are generally more secure by not allowing passwords to be specified as plain text and requiring a credential object instead (see Get-Credential), this appears not to be the case with New-SmbMapping.

  • While start is an internal cmd.exe command, PowerShell has an alias named start for its own Start-Process cmdlet; if you pass a drive specification, the two commands work the same.

    • Alternatively, you could have used the Invoke-Item cmdlet (Invoke-Item X:\),
      • which more narrowly supports opening only documents and folders, by relative or absolute paths (no $env:PATH search for executables is performed).
      • in the case of a drive-spec-only path such as X:, Invoke-Item opens File Explorer in whatever directory is current on that drive (by contrast, Start-Process and cmd.exe's start open the target drive's root directory).
like image 87
mklement0 Avatar answered Oct 29 '25 05:10

mklement0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!