PowerShell script to update value in the JSON file.

Swathi Reddy 186 Reputation points
2020-12-14T09:39:06.497+00:00

Please help in creating a PowerShell script to update the value in the JSON file. Want to get it done using paramaters not as hardcoded.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2020-12-15T01:47:20.45+00:00

    Hi,

    What is the $object? Can you post the error message? Why not just update the value as you did above

    $file.glossary.GlossDiv.GlossList.GlossEntry.SortAs=$sort_as  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2020-12-14T19:27:00.34+00:00

    On this line:

    $object.GlossEntry. = $object.roles.psobject.Properties.Value
    

    You need to correct this $object is undefined and there's a trailing period after $object.GlossEntry

    Plus, it looks like you've omitted parts of your script.

    Also, the JSON text you posted cannot be processed by the ConvertFrom-JSON cmdlet.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.