Reputation: 1175
I am new to power-shell and attempting to write a VMreset script. 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
Also it now seems as through the Write-Output is being displayed after all the commands execute.
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"
}
}
Upvotes: 1
Views: 207
Reputation: 1894
Using WS-Management to handle the copies and remove will be much faster since all tasks will be run on the remote. Actions on big files like the VM ones are very costly when done over a remote share instead of locally.
WS-Management
Upvotes: 1