Azure / Azure/terraform

Getting error ##[error]Invalid JSON primitive:

Open
#139 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
925
Forks
930
Avg merge
4d 15h
Merged PRs (30d)
5

Description

When I run Azure DevOps pipeline. I get the below error

Import-Module -Name C:\Modules\az_9.3.0\Az.Accounts\2.11.1\Az.Accounts.psd1 -Global
##[warning]Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount -ServicePrincipal -Tenant xxxxxxxxxxxxxxxx-Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
Az module initialization Complete
Beginning Script Execution
& 'D:\a\_temp\xxxxxxxxxxxxxxxxxxxxx.ps1'

Name Account SubscriptionName Environment TenantId
App name xxxxxxx.. xxxxxx. AzureCloud xxxxxxx.
Disconnect-AzAccount -Scope Process -ErrorAction Stop
Clear-AzContext -Scope Process -ErrorAction Stop
##[error]Invalid JSON primitive: .
Finishing: Configure Virtual Machine - client

**Below is my code**
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$DomainJoin,

[Parameter()]
[string]
$Groups,

[Parameter()]
[string]
$Users
)
$ErrorActionPreference = 'SilentlyContinue'

$report = ""

# Add to Domain
$Domain = Get-WmiObject win32_computersystem

if (($Domain).partofdomain -eq $true) {
$report += "Already added to Domain: $(($Domain).Domain); "
}
else {
$password = $DomainJoin | ConvertTo-SecureString -asPlainText -Force
$username = "svc-djas@wren.co.uk"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Add-Computer -DomainName "wren.co.uk" -OUPath "OU=Azure,OU=Servers,OU=Brit,DC=wren,DC=co,DC=uk" -Credential $credential
$report += "Added to Domain: $(($Domain).Domain); "

Add-LocalGroupMember -Group "Administrators" -Member "SEC-AzureCloud_Ops@wren.co.uk"
$report += "Added CloudOps to Local Admin; "
}

# Disable Local Firewall
'Domain', 'Private', 'Public' | ForEach-Object { Set-NetFirewallProfile -Profile $_ Enabled False }

# Local Admins Users and Groups
## Groups
if ($Groups.Length -gt 0) {
$adminGroups = $Groups.Split(",")
foreach ($group in $adminGroups) {
Add-LocalGroupMember -Group "Administrators" -Member $group -ErrorAction SilentlyContinue
}
}

## Users
if ($Users.Length -gt 0) {
$adminUsers = $Users.Split(",")
foreach ($user in $adminUsers) {
Add-LocalGroupMember -Group "Administrators" -Member $user -ErrorAction SilentlyContinue
}
}

Write-Output $report

#Exit
exit 0

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Azure DevOps pipeline and inspect the PowerShell output around Disconnect-AzAccount and Clear-AzContext, especially the reported Invalid JSON primitive error. Compare the command sequence with the displayed Az and AzureRM module warning; done means identifying and documenting a confirmed cause and reproducible fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.