locked
A simple power shell script to get the brief information about the drive of the system and represent the output into a excel file RRS feed

  • General discussion

  • $excel = new-object -comobject Excel.Application
    $workbooks = $excel.Workbooks.Add()
    $worksheets = $workbooks.worksheets
    $worksheet = $worksheets.Item(1)
    $worksheet.Name = “drive details”
    $worksheet.Cells.Item(1,1) = “Name”
    $worksheet.Cells.Item(1,2) = “Used”
    $worksheet.Cells.Item(1,3) = “Free”
    $worksheet.Cells.Item(1,4) = “Root”
    $a=get-psdrive
    $x=2
    $y=1
    $a
    foreach($s in $a)
    {
       if($s.Free -gt 0)
       {
       $worksheet.Cells.Item($x,$y)=$s.Name
       $y++
       $worksheet.Cells.Item($x,$y) =$s.Used
       $y++
       $worksheet.Cells.Item($x,$y) = $s.Free
       $y++
       $worksheet.Cells.Item($x,$y) =$s.Root
       $x++
       $y=1
       }
    }
    $excel.Visible=$true
    Thursday, August 8, 2013 5:42 AM

All replies

  • $excel = new-object -comobject Excel.Application
    $workbooks = $excel.Workbooks.Add()
    $worksheets = $workbooks.worksheets
    $worksheet = $worksheets.Item(1)
    $worksheet.Name = “drive details”
    $worksheet.Cells.Item(1,1) = “Name”
    $worksheet.Cells.Item(1,2) = “Used”
    $worksheet.Cells.Item(1,3) = “Free”
    $worksheet.Cells.Item(1,4) = “Root”
    $a=get-psdrive
    $x=2
    $y=1
    $a
    foreach($s in $a)
    {
       if($s.Free -gt 0)
       {
       $worksheet.Cells.Item($x,$y)=$s.Name
       $y++
       $worksheet.Cells.Item($x,$y) =$s.Used
       $y++
       $worksheet.Cells.Item($x,$y) = $s.Free
       $y++
       $worksheet.Cells.Item($x,$y) =$s.Root
       $x++
       $y=1
       }
    }
    $excel.Visible=$true
    to get the exact size in gigabytes we can use  $worksheet.Cells.Item($x,$y) =$s.Used / 1gb and similarly with free space property 
    Thursday, August 8, 2013 6:10 AM