Hi everyone,
I’m trying to customize my report for DSC, and I need help with customizing csv file.
This is just part of my CSV file:
"PSComputerName","ResourceName","InstanceName","InDesiredState","ConfigurationName","StartDate" "P5W-FR4-DSC","Script","Firewall","False","VM_ibfr4eq","11/30/2017 12:44:17 PM" "P5W-FR4-DSC","Script","HighPerformance","True","VM_ibfr4eq","11/30/2017 12:44:17 PM" "P5W-FR4-DSCTEST","Script","Firewall","True","VM_ibfr4eq","11/30/2017 12:44:18 PM" "P5W-FR4-DSCTEST","Script","HighPerformance","True","VM_ibfr4eq","11/30/2017 12:44:19 PM" "P5W-FR4-MNG-1","WindowsFeature","Telnet","False","VM_ibfr4eq","11/30/2017 12:44:23 PM" "P5W-FR4-MNG-1","WindowsFeature","SMB","False","VM_ibfr4eq","11/30/2017 12:44:23 PM"
My goal is to add new column and values. For example, If I have value InDesiredState “false”, then I want to create new column “Status” with value “False” for every computer which has at least one resource which is not in desired state, otherwise I want to create same column with value “True”.
This is example of my script, I succeeded to create column with value false, but i have problem when I’m trying to add value “True” for servers which has all resource in desired state (I get duplicate rows in CSV). Maybe this is wrong aproach, can you point me into the right direction.
$csv1 = Import-csv "C:\Users\hbasic\Desktop\results.csv" | where {$_.InDesiredState -eq "False"} $a = $csv1.pscomputername $b = $a | sort -Unique $csv = Import-Csv "C:\Users\hbasic\Desktop\results.csv" | ForEach-Object { $Data1 = 'False' $Data2 = 'True' $ServerName = $_.PScomputerName $Resource = $_.ResourceName $Instance = $_.InstanceName $State = $_.InDesiredState $Configuration = $_.ConfigurationName $Date = $_.StartDate For ($i = 0; $i -lt $b.count ; $i++) { If ($ServerName -eq $b[$i]) { $_ | Add-Member -MemberType NoteProperty -Name Status -Value $Data1 -PassThru -Force } } } | Export-Csv C:\Users\hbasic\Desktop\revised.csv
Thank you in advance!