如何使用powershell将文件从本地工作空间复制到远程服务器(不是网络共享路径)
我正试图通过TFS vNext生成定义中的“内联powershell”任务,使用powershell命令将文件从本地工作区复制到远程服务器(不是网络共享路径)。 仅供参考,目标路径不是网络共享路径 我尝试了以下命令如何使用powershell将文件从本地工作空间复制到远程服务器(不是网络共享路径),powershell,tfs,powershell-remoting,vnext,Powershell,Tfs,Powershell Remoting,Vnext,我正试图通过TFS vNext生成定义中的“内联powershell”任务,使用powershell命令将文件从本地工作区复制到远程服务器(不是网络共享路径)。 仅供参考,目标路径不是网络共享路径 我尝试了以下命令 $Session = New-PSSession -ComputerName "remote server name" -Credential "domain\username" Copy-Item "$(Build.SourcesDirectory)\Test.htm" -Des
$Session = New-PSSession -ComputerName "remote server name" -Credential "domain\username"
Copy-Item "$(Build.SourcesDirectory)\Test.htm" -Destination "C:\inetpub\wwwroot\aspnet_client\" -ToSession $Session
但是每次都会升级密码,我尝试手动输入密码,结果看起来不错
如何在不提示密码或凭据的情况下完成此步骤您确定它不在网络共享上吗?:) Powershell仅将密码作为安全字符串。您可以使用
$credential=Get credential
呈现一个非常酷的框来为您存储这些凭据,或者如果您希望以编程方式存储登录(出于明显的安全原因,不建议使用此选项):
$passwd = ConvertTo-SecureString "<password>" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("<username>",$passwd)
$passwd=converttoSecureString”“-AsPlainText-Force
$credential=新对象System.Management.Automation.PSCredential(“,$passwd)
也许有一种方法可以继承您当前的域凭据,但这远远超出了我的理解,快速的谷歌搜索什么也找不到
编辑:很抱歉,我忘了发布整件事:
$passwd = ConvertTo-SecureString "<password>" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("<username>",$passwd)
$Session = New-PSSession -ComputerName "remote server name" -Credential $credential
Copy-Item "$(Build.SourcesDirectory)\Test.htm" -Destination "C:\inetpub\wwwroot\aspnet_client\" -ToSession $Session
$passwd=converttoSecureString”“-AsPlainText-Force
$credential=新对象System.Management.Automation.PSCredential(“,$passwd)
$Session=New PSSession-ComputerName“远程服务器名称”-凭证$Credential
将项目“$(Build.SourcesDirectory)\Test.htm”-目标“C:\inetpub\wwwroot\aspnet\u client\”-复制到会话$Session
您确定它不在网络共享上吗?:)
Powershell仅将密码作为安全字符串。您可以使用$credential=Get credential
呈现一个非常酷的框来为您存储这些凭据,或者如果您希望以编程方式存储登录(出于明显的安全原因,不建议使用此选项):
$passwd = ConvertTo-SecureString "<password>" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("<username>",$passwd)
$passwd=converttoSecureString”“-AsPlainText-Force
$credential=新对象System.Management.Automation.PSCredential(“,$passwd)
也许有一种方法可以继承您当前的域凭据,但这远远超出了我的理解,快速的谷歌搜索什么也找不到
编辑:很抱歉,我忘了发布整件事:
$passwd = ConvertTo-SecureString "<password>" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("<username>",$passwd)
$Session = New-PSSession -ComputerName "remote server name" -Credential $credential
Copy-Item "$(Build.SourcesDirectory)\Test.htm" -Destination "C:\inetpub\wwwroot\aspnet_client\" -ToSession $Session
$passwd=converttoSecureString”“-AsPlainText-Force
$credential=新对象System.Management.Automation.PSCredential(“,$passwd)
$Session=New PSSession-ComputerName“远程服务器名称”-凭证$Credential
将项目“$(Build.SourcesDirectory)\Test.htm”-目标“C:\inetpub\wwwroot\aspnet\u client\”-复制到会话$Session
在将凭证传递给新PSSession
之前,应将凭证放入PSCredential对象中。有关如何创建PSCredential对象的信息,请参阅($credential
)。然后只需将该变量传递给您的命令-Credential$Credential
。您必须输入creds才能在目标服务器上创建远程会话吗?感谢@AdminOfThings的快速响应,问题已得到解决。您为什么不使用Windows计算机文件复制任务?您应该将凭据放入PSCredential对象中在将其传递到新PSSession
之前。有关如何创建pscredential对象($credential
)的信息,请参阅。然后将该变量传递给您的命令-Credential$Credential
。是否必须输入creds才能在目标服务器上创建远程会话?感谢@AdminOfThings的快速响应,问题已得到解决。您为什么不使用Windows计算机文件复制任务?