带有备用凭据的复制项目 [英] copy-item With Alternate Credentials

查看:34
本文介绍了带有备用凭据的复制项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 powershell v2 的 CTP.我编写了一个脚本,需要在我们的 dmz 中访问各种网络共享并复制一些文件.但是,我遇到的问题是,powershell 的 cmdlet(例如 copy-item、test-path 等)显然不支持备用凭据...

I'm using the CTP of powershell v2. I have a script written that needs to go out to various network shares in our dmz and copy some files. However, the issue I have is that evidently powershell's cmdlets such as copy-item, test-path, etc do not support alternate credentials...

有人对如何最好地完成我的任务有建议吗?

Anyone have a suggestion on how best to accomplish my task..?

推荐答案

我最近遇到了这个问题,并且在最新版本的 Powershell 中有一个新的 BitsTransfer 模块,允许使用 BITS,并支持使用-Credential参数.

I have encountered this recently, and in the most recent versions of Powershell there is a new BitsTransfer Module, which allows file transfers using BITS, and supports the use of the -Credential parameter.

以下示例展示了如何使用 BitsTransfer 模块使用指定的 PSCredential 对象将文件从网络共享复制到本地计算机.

The following sample shows how to use the BitsTransfer module to copy a file from a network share to a local machine, using a specified PSCredential object.

Import-Module bitstransfer
$cred = Get-Credential
$sourcePath = \\server\example\file.txt
$destPath = C:\Local\Destination\
Start-BitsTransfer -Source $sourcePath -Destination $destPath -Credential $cred

另一种处理方法是使用标准的net use"命令.但是,此命令不支持securestring"密码,因此在获得凭证对象后,您必须获得密码的解密版本才能传递给net use"命令.

Another way to handle this is using the standard "net use" command. This command, however, does not support a "securestring" password, so after obtaining the credential object, you have to get a decrypted version of the password to pass to the "net use" command.

$cred = Get-Credential
$networkCred = $cred.GetNetworkCredential()
net use \\server\example\ $networkCred.Password /USER:$networkCred.UserName
Copy-Item \\server\example\file.txt C:\Local\Destination\

这篇关于带有备用凭据的复制项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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