PowerShell Scripts on BODS via Service Acc

Hello,

I am unable to trigger powershell scripts via BODS when the BODS service is run on a Service Account. I also placed the powershell script into a .bat file and tried calling the .bat file via BODS Script which also doesn’t work.
I ve also tried setting all the execution policies, by all were in vain.


Please suggest on how to execute the PowerShell scripts on BODS via Service Account.
Version of BODS : BODS 4.1 SP2


rajnia1 (BOB member since 2011-11-17)

Have you already read this thread?


eganjp :us: (BOB member since 2007-09-12)

Many thanks for the guidance. The posts on the link supplied was helpful to know that 256 flag needs to supplied to make the job complete. I can now make my job complete by supplying 256.
But the real problem is that I am not getting the expected output though the job completes by returning NULL.Ideally it has to return 0 when it succeeds.
I am unzipping files by means of powershell Script. The .PS1 file is called via a script on BODS that is running via Service Account. As said earlier, this work perfectly fine when the services are run on Local System account or when the scripts are run on CMD.

Extract_zip.PS1 Script:

param([string]$zipfilename, [string] $destination)

if(test-path($zipfilename))
    {	
	$shellApplication = new-object -com shell.application
	$zipPackage = $shellApplication.NameSpace($zipfilename)
	$destinationFolder = $shellApplication.NameSpace($destination)
	$destinationFolder.CopyHere($zipPackage.Items())
}

None of the following worked;
BODS Script:

$G_SOURCE_FILE_NAME=‘E:\Test\Test.zip’;
$G_SOURCE_FILE_LOC=‘E:\Test’;
print(exec(‘POWERSHELL.exe’, ‘E:\Scripts\Extract_zip.ps1’||‘E:\Test\Test.zip’||‘E:\Test’ ,256));

(or)

BODS Script:

print(Exec(‘cmd’,‘E:\Bat\Test.bat’,256));

Content of Test.bat:

@echo off
C:
CD
PowerShell E:\Scripts\Extract_zip.ps1 E:\Test\Test.zip E:\Test -NoLogo -WindowsStyle Hidden


rajnia1 (BOB member since 2011-11-17)

Many thanks for the guidance. The posts on the link supplied was helpful to know that 256 flag needs to supplied to make the job complete. I can now make my job complete by supplying 256.
But the real problem is that I am not getting the expected output though the job completes by returning NULL.Ideally it has to return 0 when it succeeds.
I am unzipping files by means of powershell Script. The .PS1 file is called via a script on BODS that is running via Service Account. As said earlier, this work perfectly fine when the services are run on Local System account or when the scripts are run on CMD.

Extract_zip.PS1 Script:

param([string]$zipfilename, [string] $destination)

if(test-path($zipfilename))
    {	
	$shellApplication = new-object -com shell.application
	$zipPackage = $shellApplication.NameSpace($zipfilename)
	$destinationFolder = $shellApplication.NameSpace($destination)
	$destinationFolder.CopyHere($zipPackage.Items())
}

None of the following worked;
BODS Script:

$G_SOURCE_FILE_NAME=‘E:\Test\Test.zip’;
$G_SOURCE_FILE_LOC=‘E:\Test’;
print(exec(‘POWERSHELL.exe’, ‘E:\Scripts\Extract_zip.ps1’||‘E:\Test\Test.zip’||‘E:\Test’ ,256));

(or)

BODS Script:

print(Exec(‘cmd’,‘E:\Bat\Test.bat’,256));

Content of Test.bat:

@echo off
C:
CD
PowerShell E:\Scripts\Extract_zip.ps1 E:\Test\Test.zip E:\Test -NoLogo -WindowsStyle Hidden


rajnia1 (BOB member since 2011-11-17)

The 256 flag is a fire-and-forget call. All you’ll get back is a response indicating if the command line worked or not and it returns immediately. You’ll have to route the output of the PowerShell script to a file and then in your Data Services script poll for the file, or for a value in the file to indicate that the script is complete.


eganjp :us: (BOB member since 2007-09-12)

Thanks. I have now modified my script to pass output into a file and then I am calling the return code from the file. This outputs an empty file and returns NULL.

This again indicates that the powershell script has not worked via BODS on service account.
Is there any additional stuff that needs to be done to make powershell work via BODS which runs via a system account.?Please guide.


rajnia1 (BOB member since 2011-11-17)

Yes, you cannot run PowerShell when the Job Server service is running under the LocalSystem account. There are some work arounds to that. Check this one out: http://msviennatechnoblog.wordpress.com/2012/08/05/how-do-i-run-powershell-execommand-prompt-as-the-localsystem-account-on-windows-7/.

Alternatively, change the Job Server service to run under a network account. A local account works fine also. In the long run, changing the owner of the service is the best way to go.


eganjp :us: (BOB member since 2007-09-12)

The scenario is the reverse;
BODS services on Local System account works fine for powershell.
It doesn’t work only when the BODS service is run via a network account. Image attached showing that the BODS Service is running via network account.
BODS via Service Acc.JPG


rajnia1 (BOB member since 2011-11-17)

Be careful with your terminology. LocalSystem and Local System are the same thing to most people.

Does your network account have sufficient rights granted to it?


eganjp :us: (BOB member since 2007-09-12)

Yes all rights are granted.


rajnia1 (BOB member since 2011-11-17)

Can that network user run the PowerShell script from the command line?


eganjp :us: (BOB member since 2007-09-12)