$strPath="C:\powershell\test.xls"
$objexcel=New-Object -ComObject excel.application
$objexcel.Visible=$false
$workbook=$objexcel.Workbooks.add()
$sheet=$workbook.worksheets.item(1)
$x=2
$strComputer="."
$objwmi=Get-WmiObject -Class win32_share
$sheet.cells.item(1,1)=("Name of Share")
$sheet.cells.item(1,2)=("Description of share")
$sheet.cells.item(1,3)=("Type of share")
foreach($objshare in $objwmi)
{
$sheet.cells.item($x,1)=$objshare.Name
$sheet.cells.item($x,2)=$objshare.Description
$sheet.cells.item($x,3)=$objshare.type
$x++
}
$range=$sheet.usedrange
$range.Entirecolumn.autofit()
$objexcel.ActiveWorkbook.SaveAs($strPath)
$objexcel.quit()
$range=$null
$sheet=$null
$workbook=$null
$objexcel=$null
[gc]::collect()
时间: 2024-10-19 05:37:18