How can I add the parm of userid password for machines that need SQL authenication. In the script it passes in Server now I want 2 other pieces
a userid and password. If both blank use a trusted connection. The second piece would be to add a DateTime to the report and
store it in a Network folder like
\\server\db_inventory\filename. I would like the script just to append new days actiivity to the report.
Thanks.
#Create a new Excel object using COM $Excel = New-Object -ComObject Excel.Application $Excel.visible = $True $Excel = $Excel.Workbooks.Add() $Sheet = $Excel.Worksheets.Item(1) $intRow = 1 ForEach ($instance in Get-Content "C:\sql_servers.txt") { [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $instance $dbs=$s.Databases $intRow++ #Create column headers $Sheet.Cells.Item($intRow,1) = "Server: $s" $Sheet.Cells.Item($intRow,1).Font.Size = 12 $Sheet.Cells.Item($intRow,1).Font.Bold = $True $intRow++ $Sheet.Cells.Item($intRow,2) = "Database" $Sheet.Cells.Item($intRow,2).Font.Bold = $True $Sheet.Cells.Item($intRow,3) = "Data Name" $Sheet.Cells.Item($intRow,3).Font.Bold = $True $Sheet.Cells.Item($intRow,4) = "Data File" $Sheet.Cells.Item($intRow,4).Font.Bold = $True $sheet.Cells.Item($intRow,5) = "Data Size (MB)" $Sheet.Cells.Item($intRow,5).Font.Bold = $True $Sheet.Cells.Item($intRow,6) = "Data Used Space (MB)" $Sheet.Cells.Item($intRow,6).Font.Bold = $True $Sheet.Cells.Item($intRow,7) = "Log Name" $Sheet.Cells.Item($intRow,7).Font.Bold = $True $Sheet.Cells.Item($intRow,8) = "Log Size (MB)" $Sheet.Cells.Item($intRow,8).Font.Bold = $True $Sheet.Cells.Item($intRow,9) = "Log Used Space (MB)" $Sheet.Cells.Item($intRow,9).Font.Bold = $True $Sheet.Cells.Item($intRow,10) = "Log File" $Sheet.Cells.Item($intRow,10).Font.Bold = $True foreach ($db in $dbs) { $dbname = $db.Name $fileGroups = $db.FileGroups ForEach ($fg in $fileGroups) { # write-host $fg.files | select name If ($fg) { $intRow++ $mdfInfo = $fg.Files | Select Name, FileName, size, UsedSpace $Sheet.Cells.Item($intRow,2) = $dbname $Sheet.Cells.Item($intRow,3) = $mdfInfo.Name $Sheet.Cells.Item($intRow,4) = $mdfInfo.FileName $Sheet.Cells.Item($intRow,5) = ($mdfInfo.size / 1000) $Sheet.Cells.Item($intRow,6) = ($mdfInfo.UsedSpace / 1000) $logInfo = $db.LogFiles | Select Name, FileName, Size, UsedSpace $Sheet.Cells.Item($intRow,7) = $logInfo.Name $Sheet.Cells.Item($intRow,8) = ($logInfo.Size / 1000) $Sheet.Cells.Item($intRow,9) = ($logInfo.UsedSpace / 1000) $Sheet.Cells.Item($intRow,10) = $logInfo.FileName } } } $intRow++ } $Sheet.UsedRange.EntireColumn.AutoFit()