Tuesday, 15 April 2014

command line - Powershell script as specific user -



command line - Powershell script as specific user -

i'm having issues calling powershell script specified user , hoping has input on how troubleshoot.

i have functioning script moves files network location called "move_files.ps1". runs without issue when manually run ps console (i gather it's using credentials i'm logged in as).

in production move_files.ps1 called using oracle apex (web) front end end & windows command line. result powershell script run 'system' , user 'anonymous', not valid credentials.

what have far powershell script called "run.ps1" supposed phone call "move_files.ps1" scripts using specific credentials (that has necessary write permissions). next adopted here.

$scriptpath = split-path -parent $myinvocation.mycommand.definition $user = "domain\username" $secpass = convertto-securestring "password" -asplaintext -force $cred = new-object system.management.automation.pscredential ($user,$secpass) #call script moves csv share start-process powershell.exe -argumentlist "$scriptpath\move_files.ps1" -credential $cred

from ps console above code (run.ps1) sucessfully called , runs move_files.ps1 when run apex executed cmd command run.ps1 runs fails start move_files.ps1.

i log ps1 files opened can see when files opened. start-transcript not giving usable output. farther troubleshooting steps or input appreciated.

thanks taking time help out on this!

update 1. ps1 scripts beingness kicked off command prompt transcript start didnt output resulet. log file had generated apex & command prompt (details below output):

transcript started, output file c:\powershell\transcript0.txt start-process : command cannot executed due error: access denied. @ c:\powershell\run.ps1:22 char:15 + start-process <<<< powershell.exe -credential $cred -file "& $scriptpath\move_files.ps1" + categoryinfo : invalidoperation: (:) [start-process], invalidoperationexception + fullyqualifiederrorid : invalidoperationexception,microsoft.powershell.commands.startprocesscommand

i imagine "access error" due calling powershell command prompt because credientials used have admin access folder. next step guess getting local environment variables using line

get-childitem env:

a quick how repeating these steps: apex code calling powershell script

begin sys.dbms_scheduler.create_job( job_name => 'ps_scripts' , job_type => 'executable', job_action => 'c:\windows\system32\cmd.exe', job_class => 'default_job_class', comments => 'job test phone call out batch script on windows', auto_drop => false, number_of_arguments => 2, enabled => false); --sys.dbms_scheduler.set_job_argument_value( --this function commented out --job_name => 'ps_scripts' , --reason /q turns echo off --argument_position => 1, --& need eccho log! --argument_value => '/q'); sys.dbms_scheduler.set_job_argument_value( job_name => 'ps_scripts' , argument_position => 1, argument_value => '/c'); sys.dbms_scheduler.set_job_argument_value( job_name => 'ps_scripts' , argument_position => 2, argument_value => 'powershell "& c:\powershell\run.ps1" > "c:\powershell\log.txt"'); --pipe output here sys.dbms_scheduler.enable( 'ps_scripts' ); end;

i came across function solves issue.

the powershell background intelligent transfer service (bits) has -credential field , can transfer files using credentials business relationship other system.

i came across solution here

my move_files.ps1 code looks this:

$scriptpath = split-path -parent $myinvocation.mycommand.definition function get-pscredential($user,$password) { $secpass = convertto-securestring -asplaintext -string $password -force $creds = new-object system.management.automation.pscredential -argumentlist $user,$secpass homecoming $creds } import-module bitstransfer $destination = "\\domain.lan\shared\new_location" $credential = get-pscredential -user username -password password get-childitem -path "$scriptpath\old_location\*.csv" | foreach-object {start-bitstransfer -source $_.fullname -destination $destination -credential $credential}

move_files.ps1 can called run.ps1:

start-process powershell.exe -noprofile -executionpolicy bypass -file c:\move_files.ps1

powershell command-line oracle-apex credentials

1 comment:

  1. With more than 200 million online journals around the world, it tends to be difficult to be acknowledged in the blogosphere. As an obligingness to your perusers and individual bloggers,blog comments service

    ReplyDelete