I'm attempting to set up our first build agent for TFS 2017 On-Premise. I've taken a 2012 R2 server, installed the agent and Visual Studio 2017. The agent appears in TFS with the correct capabilities. I've taken one of the default templates for building ASP.net projects and made the minimum changes possible to it. On the first run, I can see the first few steps of getting sources and updating NuGet packages complete successfully. However the build solution step fails, and I'm struggling to understand what the issue may be.
The build log shows the following:
2017-11-15T13:16:10.3583612Z ##[section]Starting: Build solution
2017-11-15T13:16:10.3583612Z ==============================================================================
2017-11-15T13:16:10.3583612Z Task : Visual Studio Build
2017-11-15T13:16:10.3583612Z Description : Build with MSBuild and set the Visual Studio version property
2017-11-15T13:16:10.3583612Z Version : 1.119.0
2017-11-15T13:16:10.3583612Z Author : Microsoft Corporation
2017-11-15T13:16:10.3583612Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613727)
2017-11-15T13:16:10.3583612Z ==============================================================================
2017-11-15T13:16:10.8588602Z Import-Module : AuthorizationManager check failed.
2017-11-15T13:16:10.8588602Z At line:1 char:453
2017-11-15T13:16:10.8588602Z + . ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variab ...
2017-11-15T13:16:10.8588602Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-11-15T13:16:10.8588602Z + CategoryInfo : SecurityError: (:) [Import-Module], PSSecurityException
2017-11-15T13:16:10.8588602Z + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
2017-11-15T13:16:10.9677474Z Invoke-VstsTaskScript : The term 'Invoke-VstsTaskScript' is not recognized as the name of a cmdlet, function, script
2017-11-15T13:16:10.9677474Z file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
2017-11-15T13:16:10.9677474Z and try again.
2017-11-15T13:16:10.9677474Z At line:1 char:786
2017-11-15T13:16:10.9677474Z + ... tlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''\\ ...
2017-11-15T13:16:10.9677474Z + ~~~~~~~~~~~~~~~~~~~~~
2017-11-15T13:16:10.9677474Z + CategoryInfo : ObjectNotFound: (Invoke-VstsTaskScript:String) [], CommandNotFoundException
2017-11-15T13:16:10.9677474Z + FullyQualifiedErrorId : CommandNotFoundException
2017-11-15T13:16:10.9677474Z
2017-11-15T13:16:10.9989971Z ##[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name '\\hidden-unc-path\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList #{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''\\hidden-unc-path\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\VSBuild.ps1'''))"'.
2017-11-15T13:16:10.9989971Z ##[section]Finishing: Build solution
Looks like your PowerShell execution mode is set to require signed scripts to execute. The agent requires local unsigned scripts to run:
From an admin PowerShell console, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- scope LocalMachine
Then restart the agent.
Related
I was trying to build my own custom docker image with azure-powershell docker base image. As an additional feature i need to add Microsoft Graph modules (specially https://www.powershellgallery.com/packages/Microsoft.Graph.Identity.SignIns/1.10.0) in to the docker image. below are some code that i have written to achieve it.
Dockerfile
FROM mcr.microsoft.com/powershell:ubuntu-22.04
RUN pwsh -Command Set-PSRepository -Name PSGallery -InstallationPolicy Trusted && \
pwsh -Command Install-Module -Name Microsoft.Graph.Identity.SignIns -Scope AllUsers -Repository PSGallery && \
pwsh -Command Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted
ADD deployment/powershell/Main.ps1 Main.ps1
CMD ["pwsh", "-File", "Main.ps1"]
Main.ps1
Update-MgPolicyB2CAuthenticationMethodPolicy
Modules path:
ERROR
Line |
32 | Update-MgPolicyB2CAuthenticationMethodPolicy
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The term 'Update-MgPolicyB2CAuthenticationMethodPolicy' is not
| recognized as a name of a cmdlet, function, script file, or
| executable program. Check the spelling of the name, or if a
| path was included, verify that the path is correct and try
| again.
Info
powershell version: 7.2.5
Find-Module log
Name : Microsoft.Graph.Identity.SignIns
Path : /usr/local/share/powershell/Modules/Microsoft.Graph.Identit
y.SignIns/1.10.0/Microsoft.Graph.Identity.SignIns.psd1
Description : Microsoft Graph PowerShell Cmdlets
Guid : 60f889fa-f873-43ad-b7d3-b7fc1273a44f
Version : 1.10.0
ModuleBase : /usr/local/share/powershell/Modules/Microsoft.Graph.Identit
y.SignIns/1.10.0
ModuleType : Script
PrivateData : {PSData, Profiles}
AccessMode : ReadWrite
ExportedAliases : {}
ExportedCmdlets : {}
ExportedFunctions : {[Confirm-MgInformationProtectionSignature,
Confirm-MgInformationProtectionSignature],
[Confirm-MgRiskyServicePrincipalCompromised,
Confirm-MgRiskyServicePrincipalCompromised],
[Confirm-MgRiskyUserCompromised,
Confirm-MgRiskyUserCompromised],
[Get-MgDataPolicyOperation, Get-MgDataPolicyOperation]…}
ExportedVariables : {}
NestedModules : {}
Question
According to Microsoft.Graph.Identity.SignIns there are many functions present some of the functions worked fine some are not like above. There is no deprecation information given in the docs. What is the main reason for this partial load ?
enter image description here
those commands are available in MS graph powershell beta. so
You need to install the Microsoft.Graph.Beta cmdlets - https://github.com/microsoftgraph/msgraph-sdk-powershell/tree/master
I want to install Docker and so I tried the below command which gave an error
PS C:\Windows\system32> Install-Module -Name DockerMsftProvider
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'DockerMsftProvider'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\ WindowsPowerShell\ Modules\ PowerShellGet\ 1.0.0.1\ PSModule .psm1:1772 char:21 $null = PackageManagement\Install-Package #PSBoundParameters CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria, Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
even Install-Module -Name DockerMsftProvider -Repository PSGallery -Force gave the same error.
I tried the below resources and still its the same. I am not able to register a PSRepository. Only when this is installed I can install Docker in Windows Server. I spent hours to solve this still at 0% progress. Registering the PSRepository (Register-PSRepository -Default -InstallationPolicy Trusted) went fine without any errors but still its not visible.
Any possible help to solve this?
https://copdips.com/2018/05/setting-up-powershell-gallery-and-nuget-gallery-for-powershell.html
WARNING: Unable to find module repositories
Unable to find module providers
https://www.powershellgallery.com/packages/PowerShellGet/2.2.1
https://learn.microsoft.com/en-us/virtualization/windowscontainers/quick-start/set-up-environment?tabs=Windows-Server#prerequisites
Try running this, do you still get an error?
[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Install-Module -Name DockerMsftProvider -Scope AllUsers
Issue description: (Please see below screen dump for reference)
Failure using Tag with Import-AzureKeyVaultCertificate cmdlet.
The certificate would be imported into key vault okay even though I got the error message (as shown below).
However, I am not able to retrieve the certificate using Get-AzureKeyVaultCertificate cmdlet, even though I could use Get-AzureKeyVaultSecret cmdlet (Tags displayed correctly).
Additional info
• If I remove Tags from Azure portal or re-import the certificate without -Tag, I will still get the same error (Unable to cast object).
• If I delete the cert and re-import the certificate without Tags, everything is working great.
Assistance needed:
I am using 5.1.2 Azure PowerShell. Please advise what am I missing. Thanks.
PS C:\Users\tonychou> $certificateTag = #{
type = "certificate";
subjectname = "rsppe-microsoft-com";
alternatename = "dss";
environment = "Test"
};
PS C:\Users\tonychou> $certificatePasswordSecuredString = ConvertTo-SecureString $certificatePassword -AsPlainText -Force;
Import-AzureKeyVaultCertificate -VaultName $kvName -CertificateName $certInCertName -FilePath $certificatePfxFile -Password $certificatePasswordSecuredString -Tag $certificateTag;
Import-AzureKeyVaultCertificate : Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' to type 'System.Collections.Hashtable'.
At line:2 char:1
+ Import-AzureKeyVaultCertificate -VaultName $kvName -CertificateName $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Import-AzureKeyVaultCertificate], InvalidCastException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.ImportAzureKeyVaultCertificate
PS C:\Users\tonychou> $certInCertificate = Get-AzureKeyVaultCertificate -VaultName $kvName -Name $certInCertName;
Get-AzureKeyVaultCertificate : Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' to type 'System.Collections.Hashtable'.
At line:1 char:22
+ ... rtificate = Get-AzureKeyVaultCertificate -VaultName $kvName -Name $ce ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureKeyVaultCertificate], InvalidCastException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultCertificate
PS C:\Users\tonychou> $certInSecret = Get-AzureKeyVaultSecret -VaultName $kvName -Name $certInCertName;
PS C:\Users\tonychou> $certInCertificate
PS C:\Users\tonychou> $certInSecret
SecretValue : System.Security.SecureString
SecretValueText : MIIXegIBAzCCFzoGCSqGSIb3DQEHAaCCFysEghcnMIIXIzCCBgQGCSqGSIb3DQEHAaCCBfUEggXxMIIF7TCCBekGCyqGSIb3DQEMCgECoIIE9jCCBPIwHAYKKoZIhvcNAQwBAzAOBAgn0z9KUgiVSwICB9AEggTQ+38U79mo15qmAm7r0IgpGlveZFMHwqYt/LmEZOUyTKXv6GWHxkSoy/+dsa2XkVFruWas5WgqksMuwxY
43kum42JCzSHIkEzAbiN3zZNZWM7JDLaXBooR2bpOR49fdGdy44RmQjFGkU7w2cYLMjB+WSBQ9tt2xw4W1fJnv4d3vO44BQ/c2n1aHBZjmobdSrIDtpK8h+aiZyUrNix6wlifthI884h09rlF6ipBDicbgLn4NbpYPzfZlpa304fU9c7h0j/IDpdOi2zZOVT2Q3oc9ouMuSaKBC9CKE3Q99UBwyX/tZjM/A/uuW5nh3KQZ8
IJciW7/odBt3b9venZOHHbAZDns5iIzwop3hzSEDbQTqQ3hffdFEyUexHsq5AP2syveZYWlIrDpe9YJVB
PS C:\Users\tonychou> Get-Module -ListAvailable | ?{$_.Name -eq "Azure"}
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 5.1.2 Azure {Get-AzureAutomationCertificate, Get-AzureAutomationConnection, New-AzureAutomationConnection, Remove-AzureAutomationConnection...}
We suggest moving to Powershell version 6.0.0 and above
Since a while I discovered some of my buildagent doesn't have the necessary capabilities anymore to build a .NET Framwork web application. When I installed these build agents a few months ago it worked perfect. For some misterious reasons these capabilities went away. Since a week we have VS2017 installed on that machine. A reboot of the machine where the build agent is running doesn't help. Even we rebooted the Team Foundation Server machine. Can any help me with this problem?
Please try below items to let the agent to identify the capabilities:
Restart the Agent service to identify the capabilities
Add User Capabilities manually:
Settings >> AgentPools >> Select the pool >> select the specific Agent >> Capabilities >> Add capability under USER CAPABILITIES
Register capabilities to the machine following below steps, thus all the agents will automatically pick up the capabilities.
Control Panel >> System >> Advanced System Settings >> Environment Variables >> New System Variable >> Enter the variable name and value listed below >> OK >>
After doing so, restart the agents services will have each of them automatically pick up new capabilities.
Below capabilities for your reference (based on your environment and installed version):
DotNetFramework C:\Windows\Microsoft.NET\Framework64\v4.0.30319
DotNetFramework_4.6.1 C:\Windows\Microsoft.NET\Framework\v4.0.30319
DotNetFramework_4.6.1_x64 C:\Windows\Microsoft.NET\Framework64\v4.0.30319
MSBuild C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\
MSBuild_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\
MSBuild_15.0_x64 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\
VSTest C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow
VSTest_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow
VisualStudio C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\
VisualStudio_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\
VisualStudio_IDE_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\
I followed your step regarding adding the settings as user capalbility. The build agents pick up the build task now. But when the solution was build an error is returned from the build task. Exit code -1073741502 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\AgentV2_work_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList #{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\AgentV2_work_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\VSBuild.ps1'''))"'.
In general I'm trying to create mailbox on Exchange Server 2010 remotely using wmic. I have a following environment setup:
Systems are not in the same domain.
System 1 (from where I execute): running Windows 7 x64 System 2 (target system with Exchange on board): running Windows Server 2008 R2. There I have PowerShell script called addmailbox.ps1:
$secure_pwsd = convertto-securestring TESTPASSWORD -asplaintext -force
New-Mailbox -UserPrincipalName TESTMAILBOX#MYDOMAIN.com -Alias SOMEALIAS -Name SOMENAME -OrganizationalUnit Users -Password $secure_pwsd -FirstName SOMEFIRSTNAME -LastName SOMELASTNAME -DisplayName "LASTNAME FIRSTNAME" -ResetPasswordOnNextLogon $false
exit
If I run the script locally from System 2 it works fine, mailbox created as expected, so I tried to run it remotely from System 1 like this
wmic /node:IP /user:DOMAIN\Administrator /password:PASS process call create 'powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\Bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\scripts\addmailbox.ps1"'
WMIC reported that the remote process created successfully. On System 2 in task manager I can see that the process is running and child PowerShell process also spawned, but both processes are not completed. I suppose PowerShell wait for user input or something. To test, I added the key "-noninteractive" to executing command and catch the following errors
VERBOSE: Connecting to HOSTNAME
[HOSTNAME] Connecting to remote server failed with the following error message : A specified logon session does
not exist. It may already have been terminated. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportExc
eption
+ FullyQualifiedErrorId : PSSessionOpenFailed
Failed to connect to any Exchange Server in the current site.
Read-Host : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.
At C:\Program Files\Microsoft\Exchange Server\V14\bin\ConnectFunctions.ps1:47 char:18
+ $fqdn=read-host <<<< -prompt "Please enter the Server FQDN where you want to connect"
+ CategoryInfo : InvalidOperation: (:) [Read-Host], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.ReadHostCommand
VERBOSE: Connecting to
New-PSSession : Cannot bind parameter 'ConnectionUri'. Cannot convert value "http:///powershell?serializationLevel=Full
" to type "System.Uri". Error: "Invalid URI: The hostname could not be parsed."
At C:\Program Files\Microsoft\Exchange Server\V14\bin\ConnectFunctions.ps1:229 char:43
+ $session = new-pssession -connectionURI <<<< "http://$fqdn/powershell?serializationLevel=Full" -ConfigurationName Microsoft.Exchange -SessionOption $so #-erroraction silentlycontinue
+ CategoryInfo : InvalidArgument: (:) [New-PSSession], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.NewPSSessionCommand
The term 'New-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\scripts\addmailbox.ps1:3 char:12
+ New-Mailbox <<<< -UserPrincipalName TESTMAILBOX#MYDOMAIN.com -Alias SOMEALIAS -Name SOMENAME -OrganizationalUnit Users -Password $secure_pwsd -FirstName SOMEFIRSTNAME -LastName SOMELASTNAME -DisplayName "LASTNAME FIRSTNAME" -ResetPasswordOnNextLogon $false
+ CategoryInfo : ObjectNotFound: (New-Mailbox:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I repeat that these commands work fine locally on System 2. Direct specification of the FDQN in PS script file doesn't solve the problem. Please, do not suggest to use PsExec instead of WMIC or establish remote connection using PowerShells. Thanks for the advices!