“净使用"在 PowerShell 中不指定驱动器 [英] "net use" in PowerShell without specifying drive
问题描述
使用净使用",您可以执行以下操作:
With "net use", you could do the following:
net use \\server /user:domian\username
然后它会提示输入密码,并且使用任何程序(cmd、Explorer、Word 等)与该服务器建立的任何进一步 CIFS 连接都将自动使用该凭据.
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.
在 PowerShell 中是否有等效的方法来执行此操作?我知道 New-PsDrive 通常提供净使用"的答案,但它需要一个驱动器号来映射:
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?
推荐答案
cmdlet New-SMBMapping
(大体上)在功能上等同于 New-PSDrive
.但是,不需要等效参数 -LocalPath
(New-PSDrive
中的 -Name
),因此您不应收到上述错误.
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.
这篇关于“净使用"在 PowerShell 中不指定驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!