簡體   English   中英

電源殼輸出和優化

[英]Power-shell Output and optimization

我是剛接觸Power-shell並嘗試編寫VMreset腳本的人。 我一切正常,但對某些問題有一些疑問。

下面是運行幾乎所有命令的函數

我注意到有時代碼要花很長時間才能運行,而在添加End-Process,Remove-Item和Copy-Item命令之前並不需要

現在,似乎所有命令執行完后,通過Write-Output也會顯示出來。

我有更好的方法嗎?

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"
    }
}

使用WS-Management處理副本和刪除將更快,因為所有任務都將在遠程上運行。 當通過遠程共享而不是在本地共享時,對大文件(如VM文件)的操作非常昂貴。

WS管理

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM