(Export-excel/csv) Variable with date that adds one week for each new line

I’m trying to make a script that has a variable with this data:

PS L:B_DIR_BOD_OD9_IT9_07_ServicedeskScriptsPowershellIn ontwikkeling> $Global:selectedline ResourceReservationID : 65391 ResourceID : 8 ReservationDateTimeFrom : 16/06/2016 14:00:00 ReservationDateTimeTill : 16/06/2016 15:00:00 RequestedByName : Frederickx Niels (Persnr: 2573 - Telnr: 700) RequestedByEmail : nfrederickx@itg.be RequestedByIP : 10.0.17.15 ReservationStatus : Goedgekeurd Budgetnummer : 107 GewensteModaliteiten : AantalPersonen : 2 Opmerkingen : ReservationDeleted : False DateCreation : 15/06/2016 11:10:15 DateModified : 15/06/2016 14:04:35 DateDeleted : AnnulatieCode : IsGeannuleerd : False DateAnnulatie : ShowAdValvas : False OmschrijvingKort : OmschrijvingLang : Locatie : IsEvent : False Verantwoordelijke : Frederickx Niels (Persnr: 2573 - Telnr: 700) Doelstellingen : Doelpubliek : AantalPersonenMax : Programma : Frequentie : ShowWebsite : False ShowIntranet : False LokaalVoorkeur : OrganisatieType : VerantwoordelijkeExtern : VerantwoordelijkeBudget : 

I want to export this data to an excel file or csv file. Then I want to write a new line to this excel/csv and add one week to these variables:

ReservationDateTimeFrom : 16/06/2016 14:00:00 ReservationDateTimeTill : 16/06/2016 15:00:00 

So this would become:

ReservationDateTimeFrom : 23/06/2016 14:00:00 ReservationDateTimeTill : 23/06/2016 15:00:00 

And repeat this for a preconfigured amount of times. Edit: with preconfigured I mean. the scriptrunner gets a prompt to enter how many weeks he wants to add.

How would I go about doing something like that?

This is what I have so far:

$Global:SCCMSQLSERVER = "serverserver" $Global:DBNAME = "dbname" Try { $SQLConnection = New-Object System.Data.SQLClient.SQLConnection $SQLConnection.ConnectionString = "server=$SCCMSQLSERVER;database=$DBNAME;Integrated Security=True;" $SQLConnection.Open() } catch { [System.Windows.Forms.MessageBox]::Show("Failed to connect SQL Server:") } $SQLCommand = New-Object System.Data.SqlClient.SqlCommand $SQLCommand.CommandText = "SELECT * FROM resources;" $SQLCommand.Connection = $SQLConnection $SQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SQLCommand $SQLDataset = New-Object System.Data.DataSet $SqlAdapter.fill($SQLDataset) | out-null $tablevalue1 = @() foreach ($data in $SQLDataset.tables) { $Global:tablevalue1 = $data $tablevalue1 | Select-Object Resource, ResourceID | Out-GridView -OutputMode Single -Title 'select' | ForEach-Object { $Global:Resource, $Global:ResourceID = $_.Resource, $_.ResourceID } } $SQLConnection.close() $Global:SCCMSQLSERVER = "serverserver" $Global:DBNAME = "dbname" Try { $SQLConnection = New-Object System.Data.SQLClient.SQLConnection $SQLConnection.ConnectionString = "server=$SCCMSQLSERVER;database=$DBNAME;Integrated Security=True;" $SQLConnection.Open() } catch { [System.Windows.Forms.MessageBox]::Show("Failed to connect SQL Server:") } $SQLCommand = New-Object System.Data.SqlClient.SqlCommand $SQLCommand.CommandText = "SELECT * FROM resourcesReservations;" $SQLCommand.Connection = $SQLConnection $SQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SQLCommand $SQLDataset = New-Object System.Data.DataSet $SqlAdapter.fill($SQLDataset) | out-null $tablevalue2 = @() foreach ($data in $SQLDataset.tables) { $Global:tablevalue2 = $data [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null $username = [Microsoft.VisualBasic.Interaction]::InputBox("Enter name of user that needs to be disabled") Get-ADUser -LDAPFilter "(anr=$username)" -Properties mail, Name, telephoneNumber, samaccountname | select mail, Name, telephoneNumber, samaccountname | Out-GridView -OutputMode Single -Title 'select' | ForEach-Object { $Global:mail = $_.mail } $Global:selectedline = $tablevalue2 | Where {$mail -eq $_.RequestedByEmail} | Out-GridView -OutputMode Single -Title 'select' $selectedline.AnnulatieCode = $null $selectedline.ResourceID = $ResourceID } $SQLConnection.close() 

So this variable needs to repeat for each new line “$selectedline” and add one week for a preconfigured amount of times.

If you can give me some advice or point me in a good direction to look.

Thanks!

submitted by /u/FreshlyBakedMan
[link] [comments]

Leave a Reply