{$Location = "Location10"} "loc11comps.txt" {$Location = "Location11"} "computers.txt" {$Location = "Adhoc Report"} default {$Location = "Other"} } ## Save the spreadsheet to the path in the variable using the name determined from the above Switch. $SpreadSheetName = $SavePath+$Location+".xls" $workbook.Worksheets.item(1).Name = $Location ## Check to see if the spreadsheet exists. If it does, delete it and recreate it, and save it. ## Attempt to close Excel and end the ComObject. This doesn't seem to work well with Excel 2K7, ## so we are killing processes called Excel. This will close all Excel processes. If(Test-Path $SpreadSheetName){ Remove-Item $SpreadSheetName Write-host $SpreadSheetName $excel.ActiveWorkbook.SaveAs($SpreadSheetName) $excel.Quit() [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) Remove-Variable excel Get-Process -Name Excel |