I am trying to execute a PowerShell script in java windows minifi workflow using the ExecuteStreamCommand Processor (https://community.cloudera.com/t5/Support-Questions/How-to-execute-a-shell-script-while-using-NiFi-i...)
The script is working when executed manually in the PC but does not work in the workflow.
The powershell script checks the current user and if the workflow user is an admin and writes the output to a file.
The properties of the ExecuteStreamCommand Processor are as follows :
Command Path : C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
Command Arguments : -File C:\\scripts\\AdminCheck.ps1 -OutputFile C:\\Path\\adminOutput.txt
The command that works when executed on the PC :-
C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe File C:\\scripts\\AdminCheck.ps1 -OutputFile C:\\Path\\adminOutput.txt
This is the powershell script :-
param (
[string]$OutputFile = "C:\Path\adminOutput.txt"
)
# Get the current user
$CurrentUser = whoami
# Check if running as administrator
if (([System.Security.Principal.WindowsPrincipal] [System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
$AdminCheck = "Run as admin - SUCCESSFUL"
} else {
$AdminCheck = "Run as admin - FAILED"
}
# Prepare the output
$output = @(
"Current user: $CurrentUser"
$AdminCheck
)
# Write the output to the file
$output | Out-File -FilePath $OutputFile -Encoding UTF8 -Force
# Wait for 10 seconds
Start-Sleep -Seconds 10
Is there any other way I can run PowerShell scripts in Minifi . What changes can i made to my present property settings for the processor to execute the script.
Thanks all.