I have a workspace that kicks of a PowerShell script via a PythonCaller that kicks off another script under the context of another user. This works perfectly on my desktop but once uploaded to FME Server the second PowerShell script fails to execute.
The issue arises somewhere after Start-Process begins executing. The log file to which I am redirecting output is wiped out after I write to it when I create it. This is the first thing Start-Process does when RedirectStandardError parameter is used. The problem is my second log is never created which is the first step in my second script. However, no error is produced not in the FME job log or Windows Log on the server.
Has anyone tried to use Start-Process on FME Server? Are there configuration steps required by FME Server?
PythonCaller
class FeatureProcessor(object):
def __init__(self):
self.scriptOutput = str('')
process = subprocess.Popen(["powershell.exe",
"\\\\fileshare\\scripts\\RunAsSvcAcct.ps1"],
stdout=subprocess.PIPE)
self.scriptOutput = process.communicate()[0]
logger = fmeobjects.FMELogFile()
logger.logMessageString(self.scriptOutput)
pass
RunAsSvcAcct.ps1
Write-Host "RunAsSvcAcct WorkingDir: $(Get-Location)"
# Create log files
$runAsStdOut = "RunAsSvc_Paycom_StdOut-$(Get-Date -Format "yyyymmddTHHmmss").log"
$runAsStdOut = -join(".\",$runAsStdOut)
$runAsStdErr = "RunAsSvc_Paycom_StdErr-$(Get-Date -Format "yyyymmddTHHmmss").log"
$runAsStdErr = -join(".\",$runAsStdErr)
# Create credentials object
$username = "username"
$password = "password"
$securePassword = ConvertTo-SecureString $password
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
# Kick off script as service account
Write-Host "`nUpdateADUsers workingDir: $($workingDir)`n"
Start-Process powershell.exe -Credential $credential -ArgumentList (
"-executionpolicy bypass",
"-File "".\SecondScript""") -WorkingDirectory "C:\" -RedirectStandardOutput $runAsStdOut -RedirectStandardError $runAsStdErr
SecondScript.ps1
# script running another user
$runAs = "Running as $([System.Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object Name)"
Write-Host "Running as: $($runAs)"
# The Write-LogMsg creates a file if it does not yet exist
Write-LogMsg -filePath ".\mylog.log" -msg "Begin processing... `n"