Powershell Fehlende Anweisung block nach, wenn

Habe ich den Folgen code. Aber es ist {[( )]} fehlt irgendwo. Ich kann es nicht finden.
Ich in der if-Abschnitt. Aber ich weiß nicht, warum es nicht funktioniert
Wenn kann mir jemand einen Tipp geben oder etwas wird es schaffen.

Vielen Dank für das Lesen.

$date        = (get-date).AddDays(-1).ToString("yyyMMdd")
$erroractionpreference = "SilentlyContinue"

$Excel = New-Object -comobject Excel.Application 
$Excel.visible = $True

$ExcelSheet = $Excel.Workbooks.Add() 
$ExcelCell = $ExcelSheet.Worksheets.Item(1)

$ExcelCell.Cells.Item(1,1) = "Machine Name" 
$ExcelCell.Cells.Item(1,2) = "Online" 
$ExcelCell.Cells.Item(1,3) = "Drive" 
$ExcelCell.Cells.Item(1,4) = "Total size (GB)" 
$ExcelCell.Cells.Item(1,5) = "Free Space (GB)" 
$ExcelCell.Cells.Item(1,6) = "Free Space (%)" 
$ExcelCell.cells.item(1,7) = "Used Space (GB)"


$ExcelMakeup = $ExcelCell.UsedRange 
$ExcelMakeup.Interior.ColorIndex = 19 
$ExcelMakeup.Font.ColorIndex = 11 
$ExcelMakeup.Font.Bold = $True 
$ExcelMakeup.EntireColumn.AutoFit()

$intRow = 2

$colComputers = get-content "E:\servers.txt"
foreach ($strComputer in $colComputers) 
{ 
$colDisks = get-wmiobject Win32_LogicalDisk -computername $strComputer -Filter "DeviceID ='D:'" 
}

foreach ($objdisk in $colDisks) 
{

if (Test-Connection -ComputerName $strComputer -Count 1 -Quiet) 
    $ExcelCell.Cells.Item($introw, 2) = "Online"

    $ExcelCell.Cells.Item($intRow, 1) = $strComputer.ToUpper() 
    $ExcelCell.Cells.Item($intRow, 3) = $objDisk.DeviceID 
    $ExcelCell.Cells.Item($intRow, 4) = "{0:N0}" -f ($objDisk.Size/1GB) 
    $ExcelCell.Cells.Item($intRow, 5) = "{0:N0}" -f ($objDisk.FreeSpace/1GB) 
    $ExcelCell.Cells.Item($intRow, 6) = "{0:P0}" -f ([double]$objDisk.FreeSpace/[double]$objDisk.Size) 
    $ExcelCell.cells.item($introw, 7) = "{0:N0}" -f ([double]$objDisk.Size/1GB - [double]$objDisk.Freespace/1GB)

 else 

    $ExcelCell.Cells.Item($intRow, 1) = $strComputer.ToUpper() 
    $ExcelCell.Cells.Item($intRow, 2) = "Offline"
    $ExcelCell.Cells.Item($intRow, 3) = "x"
    $ExcelCell.Cells.Item($intRow, 4) = "x"
    $ExcelCell.Cells.Item($intRow, 5) = "x"
    $ExcelCell.Cells.Item($intRow, 6) = "x"
    $ExcelCell.cells.item($introw, 7) = "x"

$intRow = $intRow + 1 
}


$ExcelMakeup.EntireColumn.AutoFit() 

$Excel.ActiveWorkbook.SaveAs("E:\results\" + $date + "_" + (get-date -format "HHmm") + "_D_Drive.xlsx")
$Excel.Workbooks.Close()
$Excel.Quit()
Es gibt keine geschweiften Klammern ({} nach if oder else)
Nevermind. Ich habe bereits den Fehler gefunden. Nochmals vielen Dank !

InformationsquelleAutor Tom | 2014-06-16

Schreibe einen Kommentar