Error Running Script for another OMS workspace

Welcome Forums General PowerShell Q&A Error Running Script for another OMS workspace

This topic contains 2 replies, has 3 voices, and was last updated by

5 months, 1 week ago.

  • Author
  • #110734

    Points: 1
    Rank: Member

    Hi Experts,
    I have a script to export list of all alert rule created in OMS (Log Analytics). It is running fine and i can see result in my temp folder with name OMSAlert.csv. But when i am running same script in my another Azure subscription for a workspace i am getting error. Its bit strange and i am not ware why its is happening.
    The code is as follows:-

    param (
        #The subscription id where the OMS is located
        #The name of the OMS workspace.
        #Notification Group shortname
    $ErrorActionPreference = "Stop"
    $OutPath=$FilePath + "\OMSalerts.csv"
    #Getting all Workspaces
    $allWorkspaces = armclient get "/subscriptions/$SubscriptionId/providers/Microsoft.OperationalInsights/workspaces?api-version=2015-03-20" | ConvertFrom-Json
    ForEach($Workspace in $allWorkspaces.value)
        if($ -eq $WorkspaceID)
        $url = $
    Write-Host "Building table for results"  
    #Build a table to format the results  
    $table = New-Object system.Data.DataTable "Results"  
    $col1 = New-Object system.Data.DataColumn Name,([string])  
    $col2 = New-Object system.Data.DataColumn Description,([string])  
    $col3 = New-Object system.Data.DataColumn Threshold,([string])  
    $col4 = New-Object system.Data.DataColumn Severity,([string])  
    $col5 = New-Object system.Data.DataColumn Query,([string])  
    $col6 = New-Object system.Data.DataColumn Interval,([string])  
    $col7 = New-Object system.Data.DataColumn QueryTimeSpan,([string])  
    $col8 = New-Object system.Data.DataColumn QueryEnabled,([boolean])  
    #Get all searches
    Write-Host "Getting all searches for Workspace"  
    $Searches = armclient get "$url/savedsearches?api-version=2015-03-20" | ConvertFrom-Json
    if($Searches.value -ne $null)
    Write-Output "Searches found: $($Searches.value.count)"
    Write-Output "No searches found, exiting script"
    Write-Host "Getting schedules for Searches"  
    $ | %{
        $search = armclient get "$_/?api-version=2015-03-20" | ConvertFrom-Json
        $schedules = armclient get "$_/schedules?api-version=2015-03-20" | ConvertFrom-Json
        $schedules | %{
        $schedule = $
        $actions = armclient get "$($" | convertfrom-json
        $actions | %{
            if ($ -eq "Alert"){
            Write-Host "Alert found: $($"  
            $row = $table.NewRow()  
            $row.Name = $Name
            $row.Description = $Description  
            $row.Threshold = $Threshold.Value 
            $row.Severity = $Severity
            $row.Query = $Query
            $row.Interval = $Interval
            $row.QueryTimeSpan = $QueryTimeSpan
            $row.QueryEnabled = $QueryEnabled  
    Write-Host "Exporting results"  
    $table | Export-Csv $OutPath -NoTypeInformation

    The error which i am getting is as below:-

    convertfrom-json : Invalid JSON primitive: .
    At C:\Users\kumar_g\Downloads\retrievealerts-oms.ps1:130 char:80
    + ... et "$($" | convertfrom-json
    +                                                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

    Note:- Same script without any changes running fine for another subscription. I have also replaced api version from 2015-03-20 to 2016-04-01 but still no luck.

  • #114021

    Points: 1,634
    Helping Hand
    Rank: Community Hero

    @Gourav – Did you get the solution for this ? if so please share it with us which will be helpful for others else please update this thread with latest update.

  • #114048

    Points: 1,141
    Helping Hand
    Rank: Community Hero

    Since you are getting this..

    Invalid JSON primitive: .

    … it directly translates in most cases, to the problem is caused by a format mismatch.
    Something like, JSON that does not contain opening and closing square brackets [ ] around arrays.

    Now, all that being said, an Azure sub is a Azure sub, and there really should not be any difference in the way the data set / object is being returned to you from on to the other, but apparently there is between you subs.

    I've not encounter this with my sub, but I only have one, nor have I seen this at any customer site I supported.

    So, my suggestion is to step back a bit and look at the raw data coming back before making any convert* attempts and note any differences there, and try to resolve before further attempts.

The topic ‘Error Running Script for another OMS workspace’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort