msbuild calling powershell script under windows 7 gets signing error - powershell

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?

Related

Clojure installed, but clj fails

I installed Clojure via Powershell on Windows 10 and it installed without any errors. When I typed "clj" however, it gave me the following error:
clj : The 'clj' command was found in the module 'ClojureTools', but the module could not be loaded. For more
information, run 'Import-Module ClojureTools'.
At line:1 char:1
+ clj
+ ~~~
+ CategoryInfo : ObjectNotFound: (clj:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
I installed it to the following location: C:\Program Files\WindowsPowerShell\Modules
How can I resolve this error?
I think you need to do run:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Because your system does not allow execution of downloaded scripts. Of course decision about how much this is secure for you is completely up to you.
I'd recommend to check this tutorial, written by me:
https://github.com/littleli/scoop-clojure/wiki/Getting-started
It provides alternative, and more convenient way to install Clojure. Also it provides easy path for updates and enables access to a growing amount of utilities that you may find helpful.
Finally. If you have access to Windows Subsystem for Linux (WSL2), I'd probably go in that direction.

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.

$Branch is not recognized as an internal or external command

I'm trying to instal DVNM using this tutorial (https://blogs.msdn.microsoft.com/sujitdmello/2015/04/23/step-by-step-installation-instructions-for-getting-dnx-on-your-windows-machine/).
I did it on other notebook with Win10, I'm 8.1 embedded here and first script get me error:
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
'{$Branch' is not recognized as an internal or external command,
operable program or batch file.
Can anyone to solve my problem? No solution wherever I search and I'm stack now...
I resolved my problem, but I will leave this thread on stack. Cmd sucks, I did install by powershell just using commend to parse:
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}

How execute a powershell file in a job from Jenkins?

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)

Load assembly error when using the powershell in command line

I have a load.PS1 and it loads 'Microsoft.SqlServer.Smo' as below
[System.Reflection.Assembly]::load('Microsoft.SqlServer.Smo') | Out-Null
it works well when I use the ISE to load and run it , but get error when I run it in the powershell shell or use as "powershell -command ".\RemoveInvalidSSRSAgentJob.ps1 xxxx" as below
Exception calling "Load" with "1" argument(s): "Could not load file or assembly
'Microsoft.SqlServer.Smo' or one of its dependencies. The system cannot find t
he file specified."
At line:1 char:38
+ & {[System.Reflection.Assembly]::load <<<< ('Microsoft.SqlServer.Smo') | Out-
Null}
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
how can I set it so that it can work in the powershell shell or command?
Thanks
You can workaround using
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo')
but this method it's declared 'obsolete' from microsoft and in future can be eliminated.
The method load fails because it loads an assembly given the long form of its name but your ar passing to it a partial name: Read here.
And I find really strange that in ISE works, for me fails!