0

I have powershell task that need to load a powershell profile, but I can see that the powershell task at Azure DevOps is executed with -NoProfile.

C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted

Can we change it? I need to use a profile so that powershell.exe is aware about the proxy information.

The reason behind loading a powershell profile:

  1. Setup PowerShell Proxy accrding to PowerShell Proxy
  2. Without this setup Connect-PnP-Online fails with the following exception:

    System.Net.WebException The remote name could not be resolved: 'domainname.sharepoint.com'

sajis997
  • 1,089
  • 1
  • 15
  • 29
  • You can configure a proxy without loading a profile - the page you linked to shows how : `netsh winhttp set proxy "192.168.0.14:3128"`. But you're not going to know the proxy settings for a serverless Azure Devops build box. Neither will loading a profile help you with that. – Nick.Mc Mar 19 '20 at 14:19
  • The server is a self-hosted Azure VM – sajis997 Mar 19 '20 at 14:56
  • In that case use the method in the article to manually set the proxy – Nick.Mc Mar 19 '20 at 14:57
  • It is set, I can check the proxy setting with the command - "Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | Select-Object ProxyServer, ProxyEnable" and I can see the proxy. But Connect-PnP-Online still fails with exception mentioned initially. Do I need to look at the build agent , what kind of access it needs, so far I know that it is configured as Network Service Agent – sajis997 Mar 19 '20 at 15:04
  • I guess that tells you the system proxy is set up for, not necessarily what the powershell instance is using. Try using the syntax shown in that page to explicitly set the proxy in your script. – Nick.Mc Mar 19 '20 at 22:49
  • While trying to set it explicitly in the script gives me "Error writing proxy settings. (5) Access is denied. " in the Azure DevOps pipeline. The self-hosted agent is logged in "Network Service". I guess the agent needs to be provided more rights. How to do it ? – sajis997 Mar 20 '20 at 04:42
  • @sajis997 Not get your response for several days, would you please share your latest information about this issue? If you have any concern, feel free to share it here. – Hugh Lin Mar 24 '20 at 10:22
  • I wish I could, my effort has bogged down due to recent global crisis. Hope to come back later with this. – sajis997 Mar 26 '20 at 08:26

1 Answers1

1

For this issue , the power shell task in azure devops is executed by default with the -NoProfile argument, which is by design. The source code of the powershell task is public on github, you can view the defined argument in it.

 $arguments = "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command `". '$($filePath.Replace("'", "''"))'`""

You could submit your request for this feature on our UserVoice site, which is our main forum for product suggestions. Then you could vote that suggestion ticket and share your comment there. The product team would provide the updates if they view it.

In addition , as a workaround , you can use cmd task to invoke powershell to run the ps script. This allows you to specify the arguments that need to be supplied during execution. You can refer to this case about how to run PowerShell in CMD.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25