Debugging PowerShell -


i'm not wrong scriptlet.

i'm trying break out functionality several other functions (i have programming background not scripting 1 per se) , me logically following should execute starting @ "main" function test-sgnedmpspackage, accepting various optional parameters (the script not yet complete) when function check-path called, run, work resume in original calling function.

am missing here? on side note, how 1 return value calling function? simple return?

function checkpath($path) {     if ( test-path -path $path )          { write-host "{0} confirmed exist." -f $path }     else         { write-host "{0} not exis.\nplease check , run script again" -f $path }     exit { exit } }   function test-signedmpspackage  {     param(         [string] $pkgsource,         [string] $sigsource,         [string] $destination     )     process     {          #check  both files exist         write-host "check file existence..."           checkpath($pkgsource)         checkpath($sigsource)          #retrieve signatures file     } } 

unlike c, c++ or c# there no "main" entry point function. script @ top level - outside of function - executes. have defined 2 functions above haven't called either one. need this:

function test-signedmpspackage  {     ... }  test-signedmpspackage params 

also mentioned @bill_stewart, call defined functions call powershell commands - arguments space separated , don't use parens except evaluate expression inside parens.

as returning value function, output (output stream) not captured assigning variable or being redirected file automatically part of function's output. modify checkpath function this:

function checkpath($path) {     if (test-path -path $path) {          write-verbose "{0} confirmed exist." -f $path          $true     }     else {          write-verbose "{0} not exist.\nplease check , run script again" -f $path          $false     } } 

you can use write-host had before sometimes, perhaps in script, don't want see output. write-verbose comes in handy. set $verbosepreference = 'continue' see verbose output.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -