Dear experts!
I have 2 seperate .xls files containing information about disk space and corresponding costs. Now I need to write a script which automatically compares the columns containing the disk space of the 2 files and check wether the difference between them is greater than 10% (for example). If so, select these differing rows and create an output (either csv, html or xls). So the user can easily tell which rows need to be updated in the other file (which will later be done manually).
Here´s what I got so far:
#=============================================================================
# Open first Excel File and read from relevant sheet
#*=============================================================================
$XLSDoc = “I:\ISS\RanM\2013_Q2_Kostenaufteilung_ISS-Server.xlsm”
$SheetName = “nach TSM-Storage”
$Excel = New-Object -ComObject “Excel.Application”
$Workbook = $Excel.Workbooks.open($XLSDoc)
$Sheet = $Workbook.Worksheets.Item($SheetName)
$Sheet.Activate()
#=============================================================================
# Open second Excel File and read from relevant sheets
#*=============================================================================
$XLSDoc1 = “I:\ISS\RanM\CeBrA-Cloud_Server_2.3.xlsx”
$SheetName1 = “Abrechnung INTERN 2.3”
$Excel1 = New-Object -ComObject “Excel.Application”
$Workbook1 = $Excel1.Workbooks.open($XLSDoc1)
$Sheet1 = $Workbook1.Worksheets.Item($SheetName1)
$Sheet1.Activate()
This seems to be working so far. I can extract the values from each desired cell. For a start I tried to write a function that selects certain rows depending on the parameter $thresh:
Function SelectColumns ($thresh) {
$row = 5
$col = 3
While($Sheet.Cells.Item($row, $col).Value() -ne $null){
if($Sheet.Cells.Item($row, $col).Value() -gt $thresh){
Write-Host $Sheet.Cells.Item($row, $col-2).Value(), $Sheet.Cells.Item($row, $col).Value()
}
$row +=1
}
}
Write-Host is just for testing to see if it does what I want. This function needs to be modified to compare the values from the other xls file´s disk space column. I could use some help here.
Next is a function creating the html output for the resulting rows:
Function makeHTML{
$xlHtml = 44
$missing = [type]::Missing
$Workbook.SaveAs('H:\Documents\PowerShell\kostenvergleich.html',$xlHtml,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing) #| Where-Object -EQ $selection
}
This also works fine except that it always exports the whole sheet instead of the selected rows. I tried piping the SelectColumns function to this makeHTML function to get only the selected columns and rows for my output…but didn´t work. I know about the $input variable but not sure where to put it or if there is a completely different way to do this.
any help would be greatly appreciated!!
thanks in advance
tchintchie
PS: please keep in mind that I am a complete Powershell noob (bear with me please!)