[英]Is there a cmdlet to map network drives?
I am trying to backup database to a network file system using Backup-Sqldatabase
cmdlet in powershell. 我正在尝试使用PowerShell中的
Backup-Sqldatabase
cmdlet将数据库备份到网络文件系统。 Is there a cp_cmdshell net use
equivalent in PowerShell which can be used in PowerShell script? PowerShell脚本中是否有可用于PowerShell的
cp_cmdshell net use
等效项?
In SQL, I use below to map network drives. 在SQL中,我使用下面的映射网络驱动器。 How can I map drive in PowerShell?
如何在PowerShell中映射驱动器?
exec xp_cmdshell 'NET USE \\Backuppath "pwd" /USER:sa'
You can use the New-PSDrive cmdlet to map a network path to a drive, eg W
: 您可以使用New-PSDrive cmdlet将网络路径映射到驱动器,例如
W
:
$username = 'domain\user'
$password = 'password' | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
New-PSDrive -Name W -PSProvider FileSystem -Root '\\Backuppath' -Credential $cred
New-PSDrive –Name “Z” –PSProvider FileSystem –Root “<<network_path>>” –Persist
Above command work when the account executing it has access to the shared path. 当执行帐户的帐户有权访问共享路径时,上述命令工作。 Else, you need to provide credentials via.
否则,您需要通过提供凭据。 -credential parameter
-credential参数
I used invoke-expression with net use to map network drive and it worked fine. 我使用netoke使用invoke-expression映射网络驱动器,它工作正常。
Invoke-Expression "net use B: //backuppath pwd /user:domain\\user\u0026quot; Invoke-Expression“net use B:// backuppath pwd / user:domain \\ user”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.