Hi,
My script is not sorting the values into seperate columns for Problems,Solutions, and Impacts. Any suggestions or ideas on how I can fix this?
$allvms=Get-AzVM
$AllVmsInformation=@()
$recommendations=(Search-AzGraph -Query $query).Data
foreach($vm in $allvms)
{
$VmInfo=[PSCustomObject]@{
Name = $vm.Name
ResourceGroupName = $vm.ResourceGroupName
Location = $vm.Location
VMSize = $vm.HardwareProfile.VmSize
$query ='advisorresources | where type == "microsoft.advisor/recommendations" and properties.impactedField=="Microsoft.Compute/virtualMachines" and properties.impactedValue== "'+ $vm.Name +'"'
problem = $recommendations | Select-Object @{l='Problem';e={$_.properties.shortDescription.problem}} | ForEach-Object {$_.Problem} |Out-String
solution = $recommendations| Select-Object @{l='Solution';e={$_.properties.shortDescription.solution}}| ForEach-Object {$_.Solution} |Out-String
impact = $recommendations | Select-Object @{l='Impact';e={$_.properties.impact}}| ForEach-Object {$_.Impact} |Out-String
}
$AllVmsInformation+=$VmInfo
}
$AllVmsInformation | Export-Csv -Encoding ascii -Path C:\Users\Public\Resource.csv -Force