We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Powershell function to create an excel spreadsheet multiple sheets - and ApproveIt on workstation

kjanicke asked
Medium Priority
Last Modified: 2012-05-06
The attached code is a function I am calling.  I can call the function but something won't let me create the file.  It may be approveit related.

Error: You cannot call a method on a null-valued expression.
Exception calling "Add" with "0" argument(s): "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"
At :line:12 char:28
+ $Book = $Excel.Workbooks.Add <<<< ()

Anybody got any tips?  If I can't create the file, can anybody provide some assistance how to call a prefabbed excel file with multiple worksheets?
#----------------Function NEWEXCEL------------
Function NewExcel ($users2, $dir2)
$Excel = New-Object -Com Excel.Application
#$Excel.visible = $True
$Book = $Excel.Workbooks.Add()
$Sheet = $Book.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "User Name"
$Sheet.Cells.Item(1,2) = "Size (GB)"
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True
$sheet.name = "$dir2"
$intRow = 2
foreach ($user in $users2) {
$sheet.Cells.Item($intRow,1) = $user.MailboxDisplayName
$sheet.Cells.Item($intRow,2) = "{0,7:n2}" -f ($user.Size / 1MB)

Open in new window

Watch Question

It fails WAY before the file create.

I would do it line by line in Powershell to know exactly what fails.
Nope.  It fails at the file create.  This is not the whole script.

It is approveit.  Rather than fiddling with the settings, I just removed ApproveIt.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.