How to Structure a Payload with Include and Exclude Users in PowerShell?

0
5
Asked By TechieWizard42 On

I'm working on a script to send a payload that should include users and optionally exclude some users. Even when I'm just including users and leaving the exclude section empty, I am having issues with the payload's syntax. I would really appreciate any help on how to structure this correctly. Here's what I have so far:

$payload = @{ "include" =

{ #

@{

"id" = $userid;

} #

},

"exclude" =

{ #

@{

} #

}

}

The documentation sample for the payload looks like this:
{
"include": [
{
"id": "BETRAYEDMILK"
},
{
"id": "PURPLEMONKEYMAD"
}
],
"exclude": [
{
"id": "VIEWTIFULSTRANGER"
}
]
}

I tried changing the brackets from curly to square, but I'm still running into issues. Any insights would be greatly appreciated!

2 Answers

Answered By ScriptyMcScriptface On

It seems like you might have mixed up some syntax. For the empty lists, you shouldn’t use script blocks like {}. Instead, use an empty array like this: `exclude = @()` or you can declare it as an array: `exclude = [array]$excludeList`. This way, it won't be null but will be an empty array instead!

TechieWizard42 -

I see. Thanks for pointing that out! The expected payload format has me baffled as I keep getting errors at certain lines, especially with 'exclude'. I’ll make sure to adjust those brackets and try again.

Answered By CodeNinja99 On

Could you share what your payload looks like after converting it to JSON? That might help in spotting the problem. What was the exact JSON structure you were aiming for?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.