powershell - I'm trying to print a value for a json key that has brackets double qutoes and commas - Stack Overflow

PowerShell 5.1Line snippet of json file that's of interest:"MyAddresses": ["[emai

PowerShell 5.1

Line snippet of json file that's of interest:

"MyAddresses": ["[email protected]", "[email protected]", "[email protected]", "[email protected]"],

is there a way to print that value as is? the following prints out the value but without brackets, double quotes, and commas which is ok

# Define the path to the JSON file on the remote computers
$jsonFilePath = "C:\mydata.json"

    # Script block to run on each remote computer
    $scriptBlock = {
        param ($jsonFilePath)
        
        try {
            # Read the JSON file content
            $jsonContent = Get-Content -Path $jsonFilePath -Raw | ConvertFrom-Json
    
            # Get the value of the ReceiverAddress key
            $receiverAddress = $jsonContent.Notification.ReceiverAddresses
    
            # Output the value
            Write-Output "******************************** $($env:COMPUTERNAME) - START OF DATA ********************************************"
            Write-Output "ReceiverAddress: $receiverAddress"
            Write-Output "******************************* $($env:COMPUTERNAME) - END OF DATA *********************************************"
        }
        catch {
            Write-Output "Error on $($env:COMPUTERNAME): $_"
        }
    }
    
    # Define the list of remote computers
    $computers = 
    @"
    server1
    server2
    "@ -split [Environment]::NewLine
    
    # Run the script block on each remote computer in parallel
    $jobs = Invoke-Command -ComputerName $computers -ScriptBlock $scriptBlock -ArgumentList $jsonFilePath -AsJob
    
    # Wait for all jobs to complete
    $jobs | ForEach-Object { $_ | Wait-Job }
    
    # Retrieve and display the results
    $jobs | ForEach-Object {
        try {
            $result = Receive-Job -Job $_
            Write-Output $result
        }
        catch {
            Write-Output "Failed to retrieve job results for $($_.Location): $_"
        }
        finally {
            Remove-Job -Job $_
        }
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744737659a4590846.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信