Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 从Excel&;上的最后一行追加;动力壳_Powershell - Fatal编程技术网

Powershell 从Excel&;上的最后一行追加;动力壳

Powershell 从Excel&;上的最后一行追加;动力壳,powershell,Powershell,我目前正在编写一个脚本,可以跟踪不同网络服务器上数据库的大小。我正在将结果输出到excel,这将每天运行,因此,我需要知道如何获取包含数据的最后一行并从中追加数据 #Creates heading on an excel file if the file did not exist previously Function CreateExcelWithHeadings($intRow, $Sheet) { $intRow++ #Create column headers $Sheet.Cells

我目前正在编写一个脚本,可以跟踪不同网络服务器上数据库的大小。我正在将结果输出到excel,这将每天运行,因此,我需要知道如何获取包含数据的最后一行并从中追加数据

#Creates heading on an excel file if the file did not exist previously
Function CreateExcelWithHeadings($intRow, $Sheet)
{
$intRow++
#Create column headers
$Sheet.Cells.Item($intRow,1)= "Date"
$Sheet.Cells.Item($intRow,1).Font.Size = 12
$Sheet.Cells.Item($intRow,1).Font.Bold = $True

$Sheet.Cells.Item($intRow,2) = "Server"
$Sheet.Cells.Item($intRow,2).Font.Size = 12
$Sheet.Cells.Item($intRow,2).Font.Bold = $True

#$intRow++
$Sheet.Cells.Item($intRow,3) = "Database"
$Sheet.Cells.Item($intRow,3).Font.Bold = $True
$Sheet.Cells.Item($intRow,4) = "Data Name"
$Sheet.Cells.Item($intRow,4).Font.Bold = $True
$Sheet.Cells.Item($intRow,5) = "Data File"
$Sheet.Cells.Item($intRow,5).Font.Bold = $True
$sheet.Cells.Item($intRow,6) = "Data Size (MB)"
$Sheet.Cells.Item($intRow,6).Font.Bold = $True
$Sheet.Cells.Item($intRow,7) = "Data Used Space (MB)"
$Sheet.Cells.Item($intRow,7).Font.Bold = $True
$Sheet.Cells.Item($intRow,8) = "Log Name"
$Sheet.Cells.Item($intRow,8).Font.Bold = $True
$Sheet.Cells.Item($intRow,9) = "Log Size (MB)"
$Sheet.Cells.Item($intRow,9).Font.Bold = $True
$Sheet.Cells.Item($intRow,10) = "Log Used Space (MB)"
$Sheet.Cells.Item($intRow,10).Font.Bold = $True
$Sheet.Cells.Item($intRow,11) = "Log File"
$Sheet.Cells.Item($intRow,11).Font.Bold = $True  
}
# initalize variables 
$serverList = "C:\Database Monitor\sqlservers.txt"
$filepath ='C:\Database Monitor\Log Files\' 
$filename = 'database_logging.xlsx' 
#Create a new Excel object using COM 
$Excel = New-Object -ComObject Excel.Application
# check if file path exists, if its doesn't create one with the proper headings
If (-not (Test-Path -path $filepath))
{
New-Item -ItemType directory -Path $filepath
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
CreateExcelWithheadings 0 $Sheet
$Sheet.SaveAs($filepath+$filename)
#WritetoExcel($serverList, 0)

}
Else
{
$Excel.visible = $True
$Excel = $Excel.Workbooks.Open($filepath)
$Sheet = $Excel.Worksheets.Item(1)
$ExcelWorkSheet.activate()
#$lastRow = 
 }

相关:不是很重复,但它可能会帮助你得到你需要的。谢谢。我已经看过了,它并没有真正的帮助。我不知道他们为什么指定了一个范围。如果你能解释一下,那就太好了。