Why does custom Build Process Template executing PowerShell fail - powershell

I've modified a custom build process template to execute Powershell on the build server. This is so I can run some scripts that will automate the deployment of our SharePoint solution. Everything was working fine up until I upgraded the build servers Powershell version from 2.0 to 3.0 (which needed to be done as I was installing SCVMM Admin Console 2012 and Powershell 3.0 was a pre-requisite).
In the build template itself, I'm using a Microsoft.TeamFoundation.Build.Workflow.Activities.InvokeProcess work flow item to execute the PowerShell command with the following properties:
Arguments : String.Format(" ""& '{0}' -DropLocation '{1}' {2} "" ",
ScriptFilename, BuildDetail.DropLocation, PostDropScript2Arguments)
FileName : "powershell"
OutputEncoding :
System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.InstalledUICulture.TextInfo.OEMCodePage)
Now every time I try to execute the build, I get the following error:
Exception Message: File not found: PowerShell (type
FileNotFoundException) Exception Stack Trace: Server stack trace:
at
Microsoft.TeamFoundation.Build.Workflow.Activities.InvokeProcess.ProcessWrapper.Start()
at
Microsoft.TeamFoundation.Build.Workflow.Activities.InvokeProcess.InvokeProcessInternal.RunCommand(AsyncState
state) at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Object[]& outArgs) at
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage
msg, IMessageSink replySink)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message
reqMsg, Boolean bProxyCase) at
System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed,
MessageData& msgData) at System.Func2.EndInvoke(IAsyncResult
result) at
System.Activities.AsyncCodeActivity1.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext
context, IAsyncResult result) at
System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor
executor, BookmarkManager bookmarkManager)
Inner Exception Details:
Exception Message: The system cannot find the file specified (type
Win32Exception) Exception Stack Trace: at
System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
startInfo) at
Microsoft.TeamFoundation.Build.Workflow.Activities.InvokeProcess.ProcessWrapper.Start()
It seems like the build is no longer able to link the "powershell" command with the actual PowerShell file.
I've manually gone onto the build server and typed "powershell" into a command line and it started PowerShell, as expected.
Has anyone else experienced this issue before?
Thanks very much

Add the full filepath to powershell.exe in the invokeprocess step in your workflow and it should always work (I would not trust the environment-settings for this)
And know, logging in on the server under your own account is not equal to the build server running under a specific account.

In my case same error occurred after deploying Windows Managment Framework 3.0.
It was solved by restarting build controller and agent.

Related

Entity Framework PowerShell script cannot be loaded by Visual Studio because its operation is blocked by software restriction policies

When I load Package Manager Console within Visual Studio 2017 v15.9.6 in a project that uses Entity Framework I receive the following error:
\packages\EntityFramework.6.2.0\tools\init.ps1 cannot be loaded because its operation is blocked by software restriction
policies, such as those created by using Group Policy.
At line:1 char:45
+ ... rgs+=$_}; & 'C:\Bitbucket\project-path\packages\EntityFramework.6.2. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This prevents me from running commands specific to Entity Framework like "Update-Database" or "Add-Migration".
Here are things I have tried:
Reinstall Visual Studio
In Group Policy Editor, for both Computer Configuration and User Configuration, I have enabled the setting "Turn on Script Execution" that is located at "Administrative Templates\Windows Components\Windows PowerShell". The setting for both configurations has the "Execution Policy" set to "Allow all scripts".
I've tried locally in the Package Manager Console setting the "Process" scope to both "Bypass" and "Unrestricted", and then manually loading the Entity Framework init.ps1 script. I receive the same error.
I've also tried modifying registry keys for PowerShell to set the ExecutionPolicy to "Unrestricted" in a few places. Those places are at:
HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps120
HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps140
I've restarted multiple times in between doing all of the above.
When I run the command "Get-ExecutionPolicy -List", here are my results"
Scope ExecutionPolicy
----- -----------------------
MachinePolicy Undefined
UserPolicy Unrestricted
Process Undefined
CurrentUser Unrestricted
LocalMachine Unrestricted
After all of the above I expected to be able to just load Visual Studio as normal, launch Package Manager Console, and not receive any errors when it tries to run the Entity Framework init.ps1 script. I must be missing something or doing something incorrectly. What do I need to do to get Visual Studio to work as expected?
Some more information is that this is a computer joined to a company domain, but no other developers have this issue. There isn't a group policy set by an administrator that is trickling down preventing me from running scripts.
The error may be occurring because of an invalid certificate from Microsoft. Check in Control Panel => Internet Options => Content => Certificates on the Untrusted Publishers tab. Remove Microsoft Corporation from this list.
Sounds bizarre but it worked for me.
Tks https://github.com/NuGet/Home/issues/7158
Remove file inside
control=>internet option => content => certificates =>Untrusted publishers
then problem will solve
Try downgrading to EF 6.1.2.
I ran into the same problem as you. I tried changing the Group Execution Policies which in my case didn't work, because of some restriction on my local machine (may be set by my school admin). In another project I used 6.1.2 where things like migration was no problem.

Add-SBHost : The system cannot find the file specified

I am attempting to add a Host to a newly created Windows Service Bus 1.1 farm but regardless of what I do I eternally get the following error:
VERBOSE: [11/16/2018 2:54:06 PM]: Validating input and configuration parameters.
VERBOSE: [11/16/2018 2:54:06 PM]: Installing auto-generated certificate.
VERBOSE: [11/16/2018 2:54:16 PM]: Granting 'Log on as Service' privilege to the run as account.
VERBOSE: [11/16/2018 2:54:16 PM]: Windows Fabric configuration started.
VERBOSE: [11/16/2018 2:54:28 PM]: Windows Fabric cluster manifest generated.
VERBOSE: [11/16/2018 2:54:28 PM]: Running Windows Fabric deployment.
Add-SBHost : The system cannot find the file specified
At line:1 char:1
+ Add-SBHost -SBFarmDBConnectionString "Data Source=MYHOST;Initial C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-SBHost], Win32Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.ServiceBus.Commands.AddSBHost
I had been struggling with configuring the initial deployment of the farm because my organization uses Azure AD. I was following this very helpful Blog post to get through the installation and deployment but the issue I am seeing now isn't covered.
A Google of the issue leads me to this page where they talk about inspecting a DLL. I tried inspecting the Microsoft.ServiceBus.Commands.dll from within the Service Bus installation folder but, I'll be honest, I didn't understand enough to know what I was looking for.
Has anyone else run into this issue before? All suggestions of where I can look to find this are very much appreciated!
Based on my research of what is actually happening in Add-SBHost command, this error may occur when:
Code is trying create new temp file in %userprofile%\AppData\Local\Temp directory for something called "ClusterManifest".
Code is trying to execute FabricDeployer.exe (with created "ClusterManifest" file path as parameter) in directory which is defined in registry path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Service Bus\1.1 for variable WinFabric in folder bin\Fabric\Fabric.Code.1.0. In my case, executable was placed in C:\Program Files\Windows Fabric\bin\Fabric\Fabric.Code.1.0\FabricDeployer.exe
Code is trying to remove temp file (created in 1 point) from %userprofile%\AppData\Local\Temp
After that steps and getting message VERBOSE: [09.08.2019 13:32:26]: Windows Fabric starting. no more file operations should be performed.
What to do?
First of all check if temp file is created in %userprofile%\AppData\Local\Temp directory (sort files by modification date in explorer, run script and wait) - probably file cannot be created because of lack of permissions.
If file is creating properly and has XML inside, then check if Service Fabric is installed and FabricDeployer.exe is present in directory. In my case it wasn't there so i had to remove Windows Fabric and Service Bus. After next installation i made sure that all files were in place.
After these steps script run was successful.
I hope it will help you :)

Unable to execute "custom script extension" on Azure VM using azure CLI from linux sub system

I am working on developing post-deployment Pester validation script for my project. I need to push pester scripts into the VM as custom script extension using Azure CLI.
Following is the command I executed:
az vm extension set --resource-group SomeRG--vm-name SimpleVM --name
customScript --publisher Microsoft.Azure.Extensions --settings '{"fileUris":
["https://github.com/myname/DSCConfig/blob/master/pester.ps1"],
"commandToExecute":"powershell -ExecutionPolicy Unrestricted -File
pester.ps1"}' --version 2.0
and I got the below error in the Linux interface after executing above command:
Deployment failed. Correlation ID:
8ba16fc0-fea6-4650-bb0a-2b73c9613dfe. Handler
'Microsoft.Azure.Extensions.customScript' has reported failure for VM
Extension 'customScript' with terminal error code '1007' and error
message: 'Install failed for the plugin (name:
Microsoft.Azure.Extensions.customScript, version 2.0.6) with exception
The specified executable is not a valid application for this OS
platform.'
And while checking the extension on VM saw the status as "Transitioning " and details as Install failed for the plugin (name: Microsoft.Azure.Extensions.customScript, version 2.0.6) with exception The specified executable is not a valid application for this OS platform)
Alternatively I tried with other publishers: Microsoft.Compute and Microsoft.OSTCExtensions
Unfortunately, none of them worked. I have been stuck at this step for past two days. Any help is much appreciated.
I think you might be using the wrong custom script extension (the one you are using I believe is for Linux VMs). I think you should be using the one named "CustomScriptExtension" with a publisher of "Microsoft.Compute" and version set to "1.9" as documented here.
Specifically, try this command instead:
az vm extension set --resource-group SomeRG--vm-name SimpleVM --name CustomScriptExtension --publisher Microsoft.Compute --settings '{"fileUris": ["https://github.com/myname/DSCConfig/blob/master/pester.ps1"], "commandToExecute":"powershell -ExecutionPolicy Unrestricted -File pester.ps1"}' --version 1.9

Deploy Database Project with MSBuild with CommandLine Parameters fails

I am failing to deploy Database project using command line parameters with msbuild. I would like to:
use publish xml profile
define connection string as command line parameter
but this seems to be impossible for no reason. There is for sure some simple catch I am missing. I tried following variants:
msbuild /t:SqlDeploy /p:SqlPublishProfilePath="test.publish.xml" /p:TargetConnectionString="Data Source=..." Database.sqlproj
deploys database
values in test.pubhlish.xml are ignored
msbuild /t:Build /t:Deploy /p:SqlPublishProfilePath="test.publish.xml" /p:TargetConnectionString="Data Source=..." Database.sqlproj
deploys database
values in test.pubhlish.xml are ignored
msbuild /t:Build /t:Publish /p:SqlPublishProfilePath="test.publish.xml" /p:TargetConnectionString="Data Source=..." Database.sqlproj
fails with error: Deploy Error : The connection string is not valid
values in test.publish.xml file are used (when test.publish.xml contains TargetConnectionString, database is deployed correctly)
In all 3 cases I am using exactly the same ConnectionString, so it is not a typo or error in the connection string. I need to use the 3rd variant, but this just fails.. What am I missing?

Unable to automate the migration process using Task Scheduler and SharePoint cmdlet “MigrateUserAccount”

Unable to automate the migration process using Task Scheduler and SharePoint cmdlet “MigrateUserAccount” getting error “You cannot call a method on a null-valued expression”
$spFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$spFarm.MigrateUserAccount("$from\$name", "$to\$name", $false)
When I run the PowerShell script using the “SharePoint 2010 Management Shell” it is running and the output is successful, but when I configured the PowerShell script in Task scheduler the script is running but it throws error like “You cannot call a method on a null-valued expression”
Below screenshot displays that task scheduler is running in high privileges.
enter image description here
enter image description here
And this task has been created using the service account who administration access to this servers and added to “db_owners” in sqldatabase aswell.
Server Architecture
Web Front End 1
Web Front End 2
Application Server 1
Application Server 2
Database Cluster Node1
Database Cluster Node2
If this is all on one line...
$spFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local $spFarm.MigrateUserAccount("$from\$name", "$to\$name", $false)
...then $spFarm will not have been defined when the MigrateUserAccount function is invoked.
You'll either need to put a semicolon between the two statements, or put them on separate lines like so:
$spFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$spFarm.MigrateUserAccount("$from\$name", "$to\$name", $false)