简体   繁体   English

是否有用于映射网络驱动器的cmdlet?

[英]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.

相关问题 通过SQL SP映射到网络驱动器 - Map to Network Drive By SQL SP PHP - 模仿“地图网络驱动器”下拉列表的工作原理 - PHP - Imitate How the “Map Network Drive” Dropdown Works SQL用户名让我发疯 - SQL Username drives me crazy 用于SSD驱动器的TPC或其他数据库基准测试 - TPC or other DB benchmarks for SSD drives SQL查询以仅在本地驱动器上选择具有特定扩展名的文件 - SQL Query to select files with specific extensions on Local Drives only 无法将SQLPS CmdLet Backup-SQLDatabase与-InputObject参数一起使用 - Unable to use SQLPS CmdLet Backup-SQLDatabase with -InputObject parameter 如何打印MySQL表,计算每三个驱动程序的驱动器数量? - How to print a MySQL table that counts the number of drives per top three drivers? 在Access中,是否可以从不同驱动器的前端和后端副本的相似表中选择字段? - In Access, is it possible to select fields from similar tables in front end & back end copies on different drives? 如何使用Powershell Restore-SqlDatabase cmdlet可靠地覆盖现有数据库 - How to reliably overwrite existing database using Powershell Restore-SqlDatabase cmdlet Powershell SQL:术语“Add-SqlLogin”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称 - Powershell SQL: The term 'Add-SqlLogin' is not recognized as the name of a cmdlet, function, script file, or operable program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM