none
Powershell noob - How do you return something from a funciton?

    Question

  • Hi,

    I have the following code:

    Function CreateWorkbook ([string]$wbName)
    {
    	$xl=new-object -comObject Excel.Application
    	$wb = $xl.Workbooks.Add()
    	Write-Host $wb
    }
    #$bk = $xl.Workbooks.Open('sample.xls')
    $wbook = CreateWorkbook('name')
    $wbook.GetType()
    

    When I run it I get an error:

    You cannot call a method on a null-valued expression.
    At :line:10 char:11
    + $wbook.GetType <<<< ()

    Basically all i want to do is return the object that the function creates and store it in $wbook. How do i do that?

     

    Thanks

    Jamie


    http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | About me
    Jamie Thomson
    Thursday, October 07, 2010 11:37 PM

Answers

All replies