簡體   English   中英

使工作流程發揮作用-Powershell

[英]Make function for workflow - Powershell

我正在嘗試加快用於檢查磁盤SMART預故障狀態的腳本,因為我需要檢查兩千台計算機。 但是,腳本仍在寫出同一磁盤的狀態-計算機“主機名1”和“主機名2”具有不同的磁盤。

function disk-status (){
        param(
            [Parameter(Mandatory=$true)][string]$computername
            )
                $WMI = Get-WMIObject -Class Win32_DiskDrive
                ForEach ($Drive in $WMI){
                $disk = $Drive.Caption
                $status = $Drive.Status
                #condition will be changed to "-notmatch"
                if ($status -match "OK"){
                        #I'm using write-output to see if the script works during testing
                        Write-output $computername $disk $status
                        }
                }
}



workflow Get-disk-status {
    param(
    [string[]]$computers
  )
    foreach -parallel ($computer in $computers) {        
        disk-status -computername $computer

  }
}

#in the final version I'm going to use get-adcomputer
$computers = "hostname1", "hostname2"

Get-disk-status $computers

我得到的輸出:

hostname1
ST500LM0 21-1KJ152 SCSI Disk Device
OK
hostname2
ST500LM0 21-1KJ152 SCSI Disk Device
OK

誰能給我至少一個提示如何解決它? 先感謝您!

嘗試改變

$WMI = Get-WMIObject -Class Win32_DiskDrive 

$WMI = Get-WMIObject -Class Win32_DiskDrive -ComputerName $computername

似乎是因為您尚未將計算機傳遞給Get-WMIObject cmdlet,所以它可能正在從您所在的計算機上檢索信息。

暫無
暫無

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

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