Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error ##[error]Invalid JSON primitive: #139

Open
samanshariq opened this issue Jan 31, 2023 · 0 comments
Open

Getting error ##[error]Invalid JSON primitive: #139

samanshariq opened this issue Jan 31, 2023 · 0 comments

Comments

@samanshariq
Copy link

samanshariq commented Jan 31, 2023

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 = "[email protected]"
$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 "[email protected]"
$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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant