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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,376 Reputation points Microsoft Vendor
    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 45,096 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.