How execute a powershell file in a job from Jenkins? - powershell

Furthermore, I have the plugin for de powershell instaled.
In the configuration job, I have this:
But, I have the next error when execute the job:
.ps1 cannot be loaded because the
execution of scripts is disabled on this system. Please see "get-help about_si
gning" for more details.
At line:1 char:2
+ & <<<< 'C:\Windows\TEMP\abc.ps1'
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Build step 'Windows PowerShell' marked build as failure
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE
I think that this is because my instance of Jenkins not is administrator.
Note:
- I have a instance of Jenkins in my machine local
- And when I compile from my windows power shell console, this if execute (This is possible with this instruction "Set-ExecutionPolicy Unrestricted")

You need to set the execution policy on the server.
You can set the execution policy by typing this into your powershell window:
Set-ExecutionPolicy RemoteSigned
For more details https://technet.microsoft.com/en-us/library/ee176961.aspx

Don't run Jenkins server using service... Run jenkin server in cmd window(without window service)

Related

Powershell script run by release agent throws exception because missing .net standard 2.0

I try to run the script
Backup-SqlDatabase -ServerInstance "myserver" -Database "mydd" -BackupFile "\\mypath.bak"
This works when I log into the release target and execute the script interactively.
If I turn it into a PowerShell task in a release pipeline I get the exception
Could not load file or assembly "netstandard, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" or one of its
dependencies. The specified module could not be found.
In C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18221\SqlServer.psm1:61
Zeichen:25
+ ... $binaryModule = Import-Module -Name $binaryModulePath -PassThru
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
Process completed with exit code 0 and had 1 error(s) written to the
error stream.
I also run the PowerShell console as the user that the release agents runs as and it worked. How can I further debug this issue?
I have on premise release agents and build agents.
I also run the PowerShell console as the user that the release agents runs as and it worked. How can I further debug this issue?
According to the troubleshooting you did, it seems that the difference between powershell task and private agent powershell is causing this issue.
When I use the powershell task, we could found it not use the powershell from the priavte agent:
As workaround, you could try to use the command line task invoke the powershell from the private agent, like:
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass .\Test.ps1
Hope this helps.

System Center Service Management Automation (SMA) PowerShell Runbook Invoke-NcSsh : The system cannot find the file specified

Tried to run a powershell script inside System Center Service Management Automation (SMA) to query some informations from NetApp. The following command was used:
Invoke-NcSsh -Command "node run -node $Node sysconfig -a"
I was able to run the command successfully directly inside the PowerShell ISE on the runbook workers (NetApp_PowerShell_Toolkit_9.6.0 and putty-64bit-0.73 installed). But as soon as I was running the runbook as a SMA job it failed with the following error:
Invoke-NcSsh : The system cannot find the file specified
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-NcSsh], Win32Exception
+ FullyQualifiedErrorId :
System.ComponentModel.Win32Exception,DataONTAP.C.PowerShell.SDK.Cmdlets.Toolkit.Ssh.InvokeNcSsh
procmon.exe was showing that Orchestrator.Sandbox.exe was looking for the plink.exe (from putty used for sending ssh command) inside the following folders:
Solution:
Copy plink.exe to one of this folders.

file cannot be loaded because the execution of scripts is disabled on this system

File C:\Users\Acer\Desktop\Projelerim\BEM_CANLI\BEM\packages\EntityFramework.5.
0.0\tools\init.ps1 cannot be loaded because its execution is blocked by softwar
e restriction policies. For more information, contact your system administrator.
At line:1 char:44
+ $__pc_args=#(); $input|%{$__pc_args+=$_}; & <<<< 'C:\Users\Acer\Desktop\Proj
elerim\BEM_CANLI\BEM\packages\EntityFramework.5.0.0\tools\init.ps1' $__pc_args[
0] $__pc_args[1] $__pc_args[2]; Remove-Variable __pc_args -Scope 0
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
I get above error in package manager console. I found some solution, but I cant fix it. I tried followings
PowerShell says "execution of scripts is disabled on this system."
http://sqlish.com/file-ps1-cannot-be-loaded-because-the-execution-of-scripts-is-disabled-on-this-system-please-see-get-help-about_signing-for-more-details/
I changed execution policy,
But I allways get the same error.
It's possible that you changed the execution policy for 64-bit powershell and the package manager is running 32-bit (or vice versa).
I'd try opening 32-bit console (PowerShell (x86)) and setting the execution policy there, as the error is definitely pointing to that kind of resolution.
Make sure you restart visual studio after changing execution policy so that changes can take effect. Also make sure you changed execution policy globally with administrator username and password.
We have been facing the same issue today with Visual Studio 2017 and Entity Framework 6, and none of the solutions proposed here has worked. As a workaround, this is the temporary solution we found to be able to use Entity Framework commands in the Package Manager Console:
Execute the following commands in the Package Manager Console
Set-ExecutionPolicy -Scope Process Bypass
Import-Module "your-solution-directory/packages/EntityFramework<your EF version>/EntityFramework.psd1"
Actually, the Import-Module command is what the init1.ps1 script does.

Powershell: ExecutionPolicy is unable to be read/set

I was trying to run a powershell script (which I have run before) and received the following error:Authorizationmanager Check Failed
I figured it was the Execution Policy, so ran:
Set-ExecutionPolicy Unrestricted
I then received:
Set-ExecutionPolicy : Initialization failure
At line:1 char:20
+ set-executionpolicy <<<< unrestricted
+ CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy], ManagementException
+ FullyQualifiedErrorId : System.Management.ManagementException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
The same initialization error occurs for Get-ExecutionPolicy
Some basic commands seem to work fine, such as:
Write-Output "hi"
Can anyone suggest a fix?
Note: This is on Windows XP
Update: If I run the contents of ascript from within the powershell command prompt, it works. I only get the errors if it is run as a script. Also, Get-ExecutionPolicy and Set-ExecutionPolicy still fail from within the powershell prompt.
Make sure you are running the console as admin [Right click] then [click] "run as administrator" when you run Set-ExecutionPolicy Unrestricted.
The source of the error was due to a problem with the WMI repository. I was able to repair the repository running the following command:
Note: This is for Windows XP
rundll32 wbemupgd, UpgradeRepository
Once this was run, I was successfully able to execute Get-ExecutionPolicy, and other powershell scripts again.
A couple of links that detail repairing the WMI Repository.
Another very common case (I think this only applies post-XP), is where the .ps1 file has been 'blocked' after being downloaded from an untrusted location.
Solution: open the 'Properties' of the file in Windows Explorer, and on the 'General' tab click 'Unblock', then 'Apply' or 'OK'.
Another potential reason for this error (seen on Windows Server 2012) is that the Windows Management Instrumentation service is not running.
Starting and running the service allows for Get-ExecutionPolicy to run, and then Set-ExecutionPolicy.

msbuild calling powershell script under windows 7 gets signing error

We have a powershell build script that calls out to other scripts that is giving me trouble under Windows 7 64 bit. It works fine under XP. I've run set-executionpolicy to RemoteSigned (and also tried it with Bypass and Unrestricted). I can pull the command line from the error message and run it myself and it all runs fine.
Build errors look terrible here; but I'm including them anyway for completeness.
Project "C:\dev7\Source\DashPortal\DashboardGenerator\DashboardGenerator.csproj" (2) is building "C:\dev7\Source\DashPo
rtal\DashboardController\DashboardController.csproj" (15) on node 0 (default targets).
File C:\Users\pmckinney.NA\Documents\WindowsPowerShell\profile.ps1 cannot be lo
aded because the execution of scripts is disabled on this system. Please see "g
et-help about_signing" for more details.
At line:1 char:2
+ . <<<< 'C:\Users\pmckinney.NA\Documents\WindowsPowerShell\profile.ps1'
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
File C:\dev7\Source\DashPortal\DashboardController\..\..\..\Build\createReportI
nstallScript.ps1 cannot be loaded because the execution of scripts is disabled
on this system. Please see "get-help about_signing" for more details.
At line:1 char:87
+ C:\dev7\Source\DashPortal\DashboardController\..\..\..\Build\createReportInst
allScript <<<< -t C:\dev7\Source\DashPortal\DashboardController\..\..\..\Sourc
e\DashPortal\DashboardReports\ReportSetupScriptTemplate.sql -l C:\dev7\Source\D
ashPortal\DashboardController\..\..\..\Source\DashPortal\DashboardReports\Repor
tSetupReportList.xml -c C:\dev7\Source\DashPortal\DashboardController\..\..\..\
Source\DashPortal\Config
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
C:\dev7\Source\DashPortal\DashboardController\DashboardController.csproj(265,5): error MSB3073: The command "powershell
C:\dev7\Source\DashPortal\DashboardController\..\..\..\Build\createReportInstallScript -t C:\dev7\Source\DashPortal\Da
shboardController\..\..\..\Source\DashPortal\DashboardReports\ReportSetupScriptTemplate.sql -l C:\dev7\Source\DashPorta
l\DashboardController\..\..\..\Source\DashPortal\DashboardReports\ReportSetupReportList.xml -c C:\dev7\Source\DashPorta
l\DashboardController\..\..\..\Source\DashPortal\Config" exited with code 1.
Just guessing: You did run Set-ExecutionPolicy in your x64 PowerShell and the build runs the x86 PowerShell?
Maybe try Get-ExcutionPolicy in both shells.
Edit: oops, I see you already enabled scripts. It's possibly something to do with the context under which MSBuild is running. Are you running MSBuild as a local service account of some kind?
Edit2: It's clear the error message is deceptive. There's something else going on and the execution policy error is being thrown but not for the expected reason. Perhaps as a way to isolate, try creating another MSBuild task that runs the same line but with shorter, hardcoded paths instead of the /../../../ bonanza above?