I was working lately with PowerShell to create a script to help me later on in second part of my task. I've ended up in dead end and I am trying to get the logic for this task.
What I am trying to achieve: I got a CSV document with columns that are named always the same:
- Servername - containing hostnames
- Patchingday - dates of patching like 06/06/19
- MW - Hours of maintenance windows for servers like 00:00-04:00
I need to run through this CSV file, put in one group each server that has the same patching day and the same hours, including that date and time for later use, and do that for each of them.
What I want to do later with that is: use SCCM cmdlets to create me collections in SCCM that will be named 'customname 16.06.19 (data from Patchdate column) 23:00-02:00 (data from MW column)'.
It will include the hostnames from 'Servername' and in the settings of that collection, it will set the date of maintenance window to the same from name or any variable related to that (so in date column it will have to input date taken from Patchingday, and in hours, data taken from MW).
I don't need help with SCCM part, rather with taking data from CSV, grouping it and adding to variables. What I got to this moment is:
$global:t = @()
$t = Import-Csv xx\deploy.csv
foreach ($Obj in $t) {
$Table = [PSCustomObject]@{
HostName = $t.Servername
Date = $t.Patchingday
MW = $t.MW
}
}
#Days
foreach ($Entry in $t) {
$PD = $t.patchingday | select -Unique
}
$PD
#Hour
$g = $t.MW
$Counter = $g | select -Unique
$counter
$table[0]
I've heard that it should be done by iterating...however never done that and I am stuck here, anyone can aid or point me to a right direction?