我有好几台虚拟机,每次build完bin之后都要手动的替换到每台机器上去。更糟糕的是,远程复制粘贴总是不大好用。这个时候总是默默地感慨替bin真的是个力气活啊。多希望有这么程序可以一键替bin。(虽然最后实现的不大好,当然这是后话啦~ 各位大神帮我seesee)。
1.运行PowerShell脚本
Powershell一般初始化情况下都会禁止脚本执行。所以需要修改PowerShell的执行策略。请以管理员权限运行。
PS E:> Get-ExecutionPolicy
Restricted
PS E:> Set-ExecutionPolicy UnRestricted
2.Copy-Item
公司的大神告诉我WMI可以在别的机器上起进程。于是我找了找,结果最后找到了Copy-Item这个神奇的东西。只需要你在PowerShell里键入
Copy-Item -Path \\10.2.61.178\c$\data -Destination \\10.2.61.179\c$\root -recurse
就可以完美的搞定一部分机器啦。
说是一部分机器,是因为我的另一部分机器报错了!!!错误如下:
Copy-Item : The user name or password is incorrect.
简单地说就是,没权限。根据MSDN上说的,Copy-Item默认的用户就是当前用户。不过我比较不解的是。我所有的机器都是当前用户没有权限的啊,怎么剩下几个就能成功呢???还望来个大神解惑啊。
(MSDN上很流氓的说Copy-Item有个Credential的参数。用来通过用户名密码或者PSCredential来选择用户的。但是!这个参数不被任何安装了Windows PowerShell的机器支持。
This parameter is not supported by any providers installed with Windows PowerShell.
$Password = ConvertTo-SecureString "passwd" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($Username, $Password)
就可以完美的搞定另一部分机器啦。
说是一另部分机器,是因为我的那一部分机器报错了!!!错误如下:
New-PSDrive : Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again