Powershell:如何使用不同的用户名/密码映射网络驱动器 [英] Powershell: how to map a network drive with a different username/password

查看:1809
本文介绍了Powershell:如何使用不同的用户名/密码映射网络驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:假设我使用本地计算机上的以下PowerShell脚本自动映射某些网络驱动器。

  $ net = $(New-Object -ComObject WScript.Network); 
$ net.MapNetworkDrive(p:,\\papabox\files);

$ net = $(New-Object -ComObject WScript.Network);
$ net.MapNetworkDrive(q:,\\quebecbox\files);

##问题 - 这个不工作,因为我的用户名/密码
##是不同的romeobox
$ net = $(New-Object -ComObject WScript.Network );
$ net.MapNetworkDrive(r:,\\romeobox\files);

问题:如何修改脚本,

解决方案

 

到romeobox,即使我的romeobox上的用户名/密码不同于其他两个框code> $ net = new-object -ComObject WScript.Network
$ net.MapNetworkDrive(r:,\\romeobox\files,$ false,domain\user ,password)

应该做的,



善良,




Background: Assume I use the following powershell script from my local machine to automatically map some network drives.

$net = $(New-Object -ComObject WScript.Network);
$net.MapNetworkDrive("p:", "\\papabox\files");

$net = $(New-Object -ComObject WScript.Network);
$net.MapNetworkDrive("q:", "\\quebecbox\files");

## problem -- this one does not work because my username/password
## is different on romeobox
$net = $(New-Object -ComObject WScript.Network);
$net.MapNetworkDrive("r:", "\\romeobox\files");

Question: How do I modify the script so that I can also connect to romeobox, even though my username/password on romeobox is different from that of the other two boxes?

解决方案

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("r:", "\\romeobox\files", $false, "domain\user", "password")

Should do the trick,

Kindness,

Dan

这篇关于Powershell:如何使用不同的用户名/密码映射网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆