batch file - Missing url parameters values after running powershell script as scheduled task -


i have powershell script gets name of computer string , processes running on json array, creates parameters variables, makes web request url , has 2 parameters sent through post method shown below:

$comp_id = (get-wmiobject win32_operatingsystem) | select-object  csname | format-table -hidetableheaders | out-string $processes = get-process | where-object {$_.starttime -ne $null -and $_.mainwindowtitle.length -gt 10}  | select-object id,description,fileversion,mainwindowtitle,starttime| convertto-json  # create parameters variables $param1= @{id=$comp_id} $param2 = @{data=$processes} #the variable $process json array string  $bothparams = $param1+$param2  invoke-webrequest -uri http://my.webserver.comp:8080/galileo/peeker -method post-body $bothparams 

everything ok when run script directly i.e both parameter values accesible servlet.

i want run script scheduled task i've created batch script file calls powershell script. problem when script runs scheduled task, second parameter,supposed json array string, empty. problem?

my batch script has following 2 lines:

 @echo off # used batch script tag(%~dpn0) path (p) , file name similar file powershell.exe -command "& '%~dpn0.ps1'"  

you can run powershell scripts directly task scheduler don't need batch script. why json string ends empty, reason where-object doesn't capture anything.

adding basic debug logging script idea what's going on. example:

$logfile = "script.log"  $env:username | out-file -filepath $logfile -append get-process | select-object id, description, fileversion, mainwindowtitle, starttime `     | out-file -filepath $logfile -append 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -