I adapted this script from Michel Steveman's post on printer inventory.
#Purpose: get all file shares and output to Excel
#Create array of servers to retrieve information from by reading masterservers.txt. Could also plug in an AD query here.
$servers= get-content masterservers.txt
#create new Excel WorkBook
$Excel = new-Object -comobject Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,1) = "Server Name"
$Sheet.Cells.Item(1,2) = "Share Name"
$Sheet.Cells.Item(1,3) = "Share Path"
$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True
#Get File Share Information and write to Excel
ForEach ($server in $servers)
{
$Shares = Get-WmiObject -Class win32_share -ComputerName $server | where-object {$_.type -eq 0}
foreach ($Share in $Shares)
{
$Sheet.Cells.Item($intRow, 1) = $Server
$Sheet.Cells.Item($intRow, 2) = $Share.Name
$Sheet.Cells.Item($intRow, 3) = $Share.Path
$intRow = $intRow + 1
}
}
$WorkBook.EntireColumn.AutoFit()
$intRow = $intRow + 1
$Sheet.Cells.Item($intRow,1).Font.Bold = $True
No comments:
Post a Comment