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


hi,

i have 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 run error:

you cannot call method on null-valued expression.
@ :line:10 char:11
+ $wbook.gettype <<<< ()

basically want return object function creates , store in $wbook. how do that?

 

thanks

jamie


http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | me
jamie thomson

no worries, figured out!!

  function createworkbook ([string]$wbname)  {  	$xl=new-object -comobject excel.application  	$wb = $xl.workbooks.add()  	return $wb  }  $wbook = createworkbook('name')  $wbook.gettype()  

 


http://sqlblog.com/blogs/jamie_thomson/ | @jamiet | me
jamie thomson


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

directory stack

PowerShell List

Dns access list