I made ascript to tlist the domain admins for a non technical person to run, to list the domain admins. That works fine. I want to put a nice touch on it though and give them an Excel file to work in. I can populate the workbook just fine, but when I save it, I get an error. there are lots of references to this error, but the most common fix doesn't work, adding the 2 directories (link to fix here: http://www.techdecode.com/wp/?p=58)
Code:
cls import-module ActiveDirectory $arrUsers = @() #get list of domain admins $return = Get-ADGroupMember -Identity "domain admins" | Sort-Object #start excel environment $xl = New-Object -ComObject "Excel.Application" $xl_workbook = $xl.Workbooks.Add() $xl_worksheet = $xl_workbook.ActiveSheet $xl_cells = $xl_worksheet.Cells $row = 1 $col = 1 foreach ($user in $return) { $xl_cells.item($row, $col) = $user.name $row = $row + 1 } $xl.visible = $true #save document $date = Get-Date -Format "yyyyMMdd" $path = "c:\temp\domain_admins_$($date).xlsx" $xl_workbook.SaveAs($path)
The error I get is:
Exception calling "SaveAs" with "1" argument(s): "SaveAs method of Workbook class failed" At c:\test\Powershell Scripts\list domain admin group members.ps1:29 char:20 + $xl_workbook.SaveAs <<<< ($path) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocationAny help is appreciated!