none
Help with Convert to-Jason Cmdlets RRS feed

  • Question

  • Hi All,

    I am using invoke-webrequest to Post to a URL. I am converting some data to jason format and sending as body. But i am getting some issues with json conversion.

    My code is 

    $Name ="Ankittest"
     $path ="/ifs/dev/Ankittest"
     $group = "domain\nas_isilon_admins"
    
     $jobj1= convertto-json (New-Object PSObject -Property @{name=$name ;path=$path;permissions=@{permission="change"; permission_type ="allow" ;trustee=@{id="SID:S-1-5-21-328293959-303977128-1042822891-221341";name=$group;type="group"}} } )
    
    
    
     Invoke-RestMethod -Uri $url -Method Post -Body $jobj1 -ContentType "application/json; charset=utf-8" -WebSession $session
    

    But when i am checking the value of $jobj1 variable i am getting extra "\" in $group name "domain\nas_isilon_admins"

    PS C:\Windows\system32> $jobj1
    {
        "path":  "/ifs/dev/Ankittest",
        "name":  "Ankittest",
        "permissions":  {
                            "permission":  "change",
                            "permission_type":  "allow",
                            "trustee":  {
                                            "name":  "domain\\nas_isilon_admins",
                                            "id":  "SID:S-1-5-21-328293959-303977128-1042822891-221341",
                                            "type":  "group"
                                        }
                        }
    }
    
    Need to remove one "\" from the domain\\nas_isilon_admins.


    • Moved by Bill_Stewart Thursday, January 25, 2018 10:47 PM Help vampire
    Thursday, November 23, 2017 1:07 AM

All replies

  • Yes.  The backslash has to be escaped.  The forward slashes do mot get escaped.\

    This is normal.

    Do this without trying to jam everything on one line.  It is unnecessary and impossible to read or debug.

    $Name = 'Ankittest'
    $path = '/ifs/dev/Ankittest'
    $group = 'domain\nas_isilon_admins'
    
    $obj = [pscustomobject]@{
            name = $name
            path = $path
            permissions = @{
                permission = 'change'
                permission_type = 'allow'
                trustee = @{
                            id = 'SID:S-1-5-21-328293959-303977128-1042822891-221341'
                            name = $group
                            type = 'group' 
                        }
                }
            }
    $jobj1 = $obj | convertto-json
       


    \_(ツ)_/

    Thursday, November 23, 2017 2:25 AM