Access denied to powershell.exe Start-Process from Jenkins descriptive pipeline - powershell

I am very new to Jenkins. I have installed it locally on my Windows 10, with no slaves, only the master agent.
Then I created the following declarative pipeline:
pipeline {
agent any
stages {
stage('Stage 1: Running TSextract') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
powershell 'Start-Process -FilePath E:\\my-config\\bin2\\RemoteRunner.exe -ArgumentList "dummy.azurecr.io/my-extract:1.10.13 E:\\my-config test-79 -t td TSextract"'
}
}
}
}
}
When I run this command in PowerShell from the command line everything happens as it should: Start-Process -FilePath E:\my-config\bin2\RemoteRunner.exe -ArgumentList "dummy.azurecr.io/my-extract:1.10.13 E:\my-config test-79 -t td TSextract"
However, through Jenkins, via the above descriptive pipeline, this results in the following error:
powershell.exe : Start-Process : This command cannot be run due to the error: Access is denied.
At C:\windows\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\LocalPipeline#tmp\durable-eb81f70f\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Start-Process :...cess is denied. :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
At C:\windows\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\work
space\LocalPipeline#tmp\durable-eb81f70f\powershellScript.ps1:1 char:1
+ Start-Process -FilePath E:\my-config\bin2\RemoteRunner.exe -Argument ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp
erationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
ommands.StartProcessCommand
So the question is what/ how exactly do I grant permissions to Start-Process from Jenkins?

Related

Cannot access network shared drive in unattended mode using powershell

I am new to powershell so would need need to resolve this issue.
We are trying to execute a powershell script via Azure devops pipelines and the script is made to access a network shared drive to identify a particular file.
The script runs perfectly fine in the gui session and is able to get the file.
However when we run it from AZ pipelines, it fails stating the access is denied.
The user being used in AZ Pipelines has admin access over the file.
The N/w drive path looks something like this.
\\ServerName\builds\PACKAGES\MainMasterBuildDrop\MainScheduledBuild\axmodel
Code ::
$locr = "\\ServerName\builds\PACKAGES\MainMasterBuildDrop\MainScheduledBuild\axmodel"
$axfiler = Get-ChildItem -Path $locr | Select FullName | ft -hidetableheaders | Out-String
$filever = $($($axfiler.split("\")[-1]).Split("_")[-1]).Replace(".axmodel", "")
Error ::
2022-01-14T07:19:22.6339088Z o -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\User
2022-01-14T07:19:22.6339869Z s\SRV_Deployment\AppData\Local\Temp\61e3d867-9d07-41cc-91c1-c4a04717bc2d
2022-01-14T07:19:22.6340311Z .ps1'"
2022-01-14T07:19:22.6340436Z
2022-01-14T07:19:22.7446332Z ls : Access is denied
2022-01-14T07:19:22.7446823Z At line:1 char:1
2022-01-14T07:19:22.7447184Z + & 'C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo ...
2022-01-14T07:19:22.7447867Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-01-14T07:19:22.7448434Z + CategoryInfo : NotSpecified: (ls : Access is denied:String) [],
2022-01-14T07:19:22.7448858Z RemoteException
2022-01-14T07:19:22.7449188Z + FullyQualifiedErrorId : NativeCommandError
2022-01-14T07:19:22.7449545Z
2022-01-14T07:19:22.7449643Z
2022-01-14T07:19:22.7618724Z At E:\DeploymentTeam\Scripts\DeploymentValidation\Test.ps1:1 char:1
2022-01-14T07:19:22.7619629Z + ls "\\Server\builds\PACKAGES\MainMasterBuildDrop\ ...
2022-01-14T07:19:22.7620370Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-01-14T07:19:22.7620732Z
2022-01-14T07:19:22.7620874Z
2022-01-14T07:19:22.7731192Z + CategoryInfo : PermissionDenied: (\\ServerName\...edBuild\axmo
2022-01-14T07:19:22.7731830Z del:String) [Get-ChildItem], Unauthoriz
2022-01-14T07:19:22.7732125Z
2022-01-14T07:19:22.7732299Z
2022-01-14T07:19:22.7845365Z edAccessException
2022-01-14T07:19:22.7845602Z
2022-01-14T07:19:22.7846744Z
2022-01-14T07:19:22.7966282Z + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.Power
2022-01-14T07:19:22.7966826Z Shell.Commands.GetChildItemCommand
2022-01-14T07:19:22.7966978Z
2022-01-14T07:19:22.7967080Z

When running a powershell script via Jenkins getting this error : "NativeCommandError" not sure how to use invoke-command

Ignoring an errorlevel != 0 in Windows PowerShell (ISE)
I have read this link but not sure how to run "Invoke-Command" my $ErrorActionPreference is "continue".
This is the error I am getting :
06:06:55 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command '& ''E: ...
06:06:55 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
06:06:55 + CategoryInfo : NotSpecified: (root : 2020-10-...something:String) [], RemoteException
06:06:55 + FullyQualifiedErrorId : NativeCommandError
The $errorActionPreference should be defined inside the scriptblock like:
Invoke-Command {$ErrorActionPreference = 'SilentlyContinue'; REST OF THE CODE}

'Provider load failure' during installation process

I execute two Powershell scripts during a installation process from a desktop application under Windows 10 IoT Enterprise.
%WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -File ".\KeyboardFilter.ps1"
%WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -File ".\ShellLauncher.ps1"
But the execution of the Powershell scripts is not successful. I get the following errors:
Get-WMIObject : Provider load failure
At C:\Program Files\Application\KeyboardFilter.ps1:31 char:19
+ ... $predefined = Get-WMIObject -class WEKF_PredefinedKey #CommonParams |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Write-Error : A positional parameter cannot be found that accepts argument 'is'.
At C:\Program Files\Application\KeyboardFilter.ps1:41 char:9
+ Write-Error $Id is not a valid predefined key
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Write-Error], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteErrorCommand
enable-windowsoptionalfeature : An attempt was made to load a program with an incorrect format.
At C:\Program Files\Application\ShellLauncher.ps1:4 char:1
+ enable-windowsoptionalfeature -online -featureName Client-EmbeddedShe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
The installation process starts with administration permissions.
The first script adds key combinations to the Keyboard Filter (Windows 10 IoT feature).
The second scripts enable and configure the Shell Launcher (also Windows 10 IoT feature).
KeyboardFilter.ps1:
param (
[String] $ComputerName
)
$CommonParams = #{"namespace"="root\standardcimv2\embedded"}
$CommonParams += $PSBoundParameters
function Enable-Predefined-Key($Id) {
$predefined = Get-WMIObject -class WEKF_PredefinedKey #CommonParams |
where {
$_.Id -eq "$Id"
};
if ($predefined) {
$predefined.Enabled = 1;
$predefined.Put() | Out-Null;
Write-Host Enabled $Id
} else {
Write-Error $Id is not a valid predefined key
}
}
If I execute the Powershell scripts in a batchfile or on Powershell console, everything works fine. I also tried to execute the Powershell scripts during the installation process with Powershell x86 and x64, same errors in both cases.
Any hints, tips or solution for this problem?

Start-Process : This command cannot be run due to the error: Unknown error (0xffffffff)

I am trying to set up NativeScript on Windows. I am following the steps from the site and when I type this:
#powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))"
I get this error:
Start-Process : This command cannot be run due to the error: Unknown error
(0xffffffff).
At line:25 char:2
+ Start-Process -FilePath PowerShell.exe -Verb Runas -Wait -Argumen ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

Powershell codes throwing errors on Jenkins

I've added the following line of Powershell codes in Jenkins and it's throwing some errors, although it's working fine when I'm trying to execute it via Powershell ISE on the same desktop/machine.
I have configured the Jenkins service logon and the user ID got correct permission.
Kindly advise.
servers = Get-Content "C:\tmp\script\updated\SessionHost.txt"
foreach ($server in $servers)
{
$FolderWindows = Start-Process -FilePath "\\$server\C$\Temp" -WindowStyle Maximized
}
Error Message on Jenkins:
Start-Process : This command cannot be run due to the error: Server execution
failed.At C:\tmp\script\updated\MainTaiwanUAT.ps1:385 char:22
+ $FolderWindows = Start-Process -FilePath "\\$server\C$\Temp"
-WindowS ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp
erationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
ommands.StartProcessCommand