Maarten Vissers
Maarten Vissers

Reputation: 699

DevOps registration script error: Current() ).IsInRole(...)

I can't get my registration script to run in PowerShell (admin). It works in Powershell ISE, but then the script is stuck at "Connecting to the server..."

Am I doing something wrong?

enter image description here

This is the script:

 $ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive\'azagent')){mkdir $env:SystemDrive\'azagent'}; cd $env:SystemDrive\'azagent'; for($i=1; $i -lt 100; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWD\agent.zip";$DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy;$securityProtocol=@();$securityProtocol+=[Net.ServicePointManager]::SecurityProtocol;$securityProtocol+=[Net.SecurityProtocolType]::Tls12;[Net.ServicePointManager]::SecurityProtocol=$securityProtocol;$WebClient=New-Object Net.WebClient; $Uri='[url]';if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){$WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True);}; $WebClient.DownloadFile($Uri, $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD");.\config.cmd --deploymentgroup --deploymentgroupname "Production" --agent $env:COMPUTERNAME --runasservice --work '_work' --url '[devopsUrl]' --projectname 'Storms' --auth PAT --token [token]; Remove-Item $agentZip;

Upvotes: 4

Views: 946

Answers (2)

Maarten Vissers
Maarten Vissers

Reputation: 699

The quotation marks are the issue. There are multiple types of quotation marks and depending on your country of residence this can cause issues.

This can be solved by removing the quotation marks around "Administrator" and adding them back manualy.

You can see the difference here: “Administrator” versus "administrator"

Notice the difference in the quotation marks? The first pair is american and the second is the european version.

Upvotes: 10

AjayKumarGhose
AjayKumarGhose

Reputation: 4893

To resolve the above issue we need to run the script on Windows PowerShell (Run as Administrator)

enter image description here

For more information Please refer the below links:

Upvotes: -1

Related Questions