admin管理员组文章数量:1391964
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 $_
}
}
本文标签:
版权声明:本文标题:powershell - I'm trying to print a value for a json key that has brackets double qutoes and commas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744737659a2622428.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论