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


  • 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')

    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?



    Jamie | @jamiet | About me
    Jamie Thomson
    Thursday, October 07, 2010 11:37 PM


All replies