“net use” in PowerShell without specifying drive

北城以北 提交于 2020-12-08 07:57:44

问题


With "net use", you could do the following:

net use \\server /user:domian\username

It would then prompt for a password, and any further CIFS connections made to that server using any program (cmd, Explorer, Word, etc) would automatically use that credential.

Is there an equivalent way of doing this in PowerShell? I know New-PsDrive usually provides the answer for "net use", but it requires a drive letter to map:

PS C:\WINDOWS\system32> New-PsDrive -PSProvider FileSystem -Root \\server -Credential domain\user
cmdlet New-PSDrive at command pipeline position 1
Supply values for the following parameters:
Name: 
New-PSDrive : Cannot bind argument to parameter 'Name' because it is an empty string.
At line:1 char:1
+ New-PsDrive -PSProvider FileSystem -Root \\server -Credential domain ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-PSDrive], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.NewPSDriveCommand

I don't want to map a drive, I just want to say "when I connect to this server, use this credential". Is there a way?


回答1:


The cmdlet New-SMBMapping is (by and large) functionally equivalent to New-PSDrive. However, the equivalent parameter -LocalPath (-Name in New-PSDrive) is not required so you shouldn't get the above error.




回答2:


net use * \server\share /options



来源:https://stackoverflow.com/questions/40009297/net-use-in-powershell-without-specifying-drive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!