Skip to main content
Shw123
Silver ⭐️
January 23, 2025
Question

Unable to execute powershell script using MiNiFi ExecuteStreamCommand Processor

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-in-Windows/td-p/153638)

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.




1 reply

VidyaSargur
Community Manager
Community Manager
January 23, 2025

@Shw123, Welcome to our community! To help you get the best possible answer, I have tagged our NiFi experts @MattWho @SAMSAL  who may be able to assist you further.

Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.

Translate
Regards, Vidya Sargur, Community Manager Was your question answered? Make sure to mark the answer as the accepted solution. If you find a reply useful, say thanks by clicking on the thumbs up button.