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条)