[英]Power-shell Output and optimization
I am new to power-shell and attempting to write a VMreset script. 我是刚接触Power-shell并尝试编写VMreset脚本的人。 I have everything working but have a few questions about some things.
我一切正常,但对某些问题有一些疑问。
Below is the function that runs pretty all the commands 下面是运行几乎所有命令的函数
I notice that sometimes it takes forever the for the code to run, it didn't before I added the End-Process, Remove-Item and Copy-Item Commands 我注意到有时代码要花很长时间才能运行,而在添加End-Process,Remove-Item和Copy-Item命令之前并不需要
Also it now seems as through the Write-Output is being displayed after all the commands execute. 现在,似乎所有命令执行完后,通过Write-Output也会显示出来。
Is there a better way for me to be doing this? 我有更好的方法吗?
function OS-Windows7 {
Foreach ($Computer in $global:ComputerList) {
Write-Output "Starting VMReset on $Computer"
Write-Output "Looking for active VMWare Processes to kill on $Computer"
End-Process 'vmware-vmx'
End-Process 'vmware'
End-Process 'vmware-tray'
Write-Output "Removing altered virtual machines on $Computer"
Remove-Item \\$Computer\C$\"My Virtual Machines\*" -Force -Recurse
Write-Output "Replacing altered virtual machines on $Computer"
Copy-Item "\\$Computer\C$\Program Files (x86)\VMware\VMware Workstation\VM\Child\*" "\\$Computer\C$\My Virtual Machines\" -recurse -force
Write-Output "VMReset Finished on $Computer"
}
}
Using WS-Management to handle the copies and remove will be much faster since all tasks will be run on the remote. 使用WS-Management处理副本和删除将更快,因为所有任务都将在远程上运行。 Actions on big files like the VM ones are very costly when done over a remote share instead of locally.
当通过远程共享而不是在本地共享时,对大文件(如VM文件)的操作非常昂贵。
WS-Management WS管理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.