sync
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
$CurrentCsv = Import-Csv -Path "D:\OneDrive - State of North Dakota\RitmExportStorage.csv"
|
||||
$NewestRecord = $CurrentCsv | Sort-Object -Descending number | select -First 1
|
||||
[datetime]$StartDate = $NewestRecord.opened_at
|
||||
#$StartDate = Get-date -Year 2020 -Month 1 -Day 1
|
||||
[datetime]$EndDate = Get-Date #-Year 2023 -Month 3 -Day 30
|
||||
|
||||
$filter = @('cat_item', '-eq', '7c2457ae1bbfc9d06bc5cb751a4bcb69'),
|
||||
'-and',
|
||||
@('opened_at', '-gt', $StartDate ),
|
||||
'-and',
|
||||
@('opened_at', '-lt', $EndDate )
|
||||
|
||||
$RecordSearch = Get-ServiceNowRecord -Table 'Requested Item' -Filter $Filter -IncludeTotalCount | Sort-Object Number
|
||||
|
||||
$CurrentCsv = Import-Csv -Path "D:\OneDrive - State of North Dakota\RitmExportStorage.csv"
|
||||
ForEach ($Record in $RecordSearch) {
|
||||
Write-Warning -Message ("Begin record " + $Record.number)
|
||||
If ( @($CurrentCsv.number | Where-Object { $_ -eq $Record.Number }).count -gt 0) {
|
||||
Write-Warning -Message ("Number " + $Record.Number + " already in csv")
|
||||
# do nothing
|
||||
}
|
||||
Else {
|
||||
#Write-Warning -Message $record.number
|
||||
$RecordDetail = Get-ServiceNowRecord -Table 'Requested Item' -ID $Record.Number -IncludeCustomVariable
|
||||
|
||||
ForEach ($Record in $RecordDetail) {
|
||||
$RecordsToExport = [System.Collections.ArrayList]@()
|
||||
$obj = [PSCustomObject][ordered]@{
|
||||
'number' = $Record.number;
|
||||
'sys_id' = $Record.sys_id;
|
||||
'opened_at' = $Record.opened_at;
|
||||
'requested_for' = $Record.requested_for.display_value;
|
||||
'short_description' = $Record.short_description;
|
||||
'description' = $Record.short_description;
|
||||
'additional_comments' = ($Record.CustomVariable | Where-Object Name -EQ 'additional_comments').Value
|
||||
'request_type' = ($Record.CustomVariable | Where-Object Name -EQ 'request_type').Value
|
||||
'array_name' = ($Record.CustomVariable | Where-Object Name -EQ 'array_name').Value
|
||||
'size' = ($Record.CustomVariable | Where-Object Name -EQ 'size').Value
|
||||
'units' = ($Record.CustomVariable | Where-Object Name -EQ 'units').Value
|
||||
'abr' = ($Record.CustomVariable | Where-Object Name -EQ 'abr').Value
|
||||
'volume_name' = ($Record.CustomVariable | Where-Object Name -EQ 'volume_name').Value
|
||||
}
|
||||
|
||||
ForEach ($Property in $Record.PSObject.Properties) {
|
||||
If ($obj.PSObject.Properties.Name -match $Property.Name) {
|
||||
#Write-Verbose -Message ("Property " + $Property.Name + " already in obj")
|
||||
}
|
||||
Else {
|
||||
$obj | Add-Member -MemberType $Property.MemberType -Name $Property.Name -Value $Property.Value -TypeName $Property.TypeNameOfValue -Verbose
|
||||
}
|
||||
}
|
||||
ForEach ($Property in $Record.CustomVariable) {
|
||||
If ($obj.PSObject.Properties.Name -match $Property.Name) {
|
||||
#Write-Verbose -Message ("Property " + $Property.Name + " already in obj")
|
||||
}
|
||||
Else {
|
||||
$obj | Add-Member -MemberType NoteProperty -Name $Property.Name -Value $Property.Value
|
||||
}
|
||||
}
|
||||
$null = $RecordsToExport.Add($obj)
|
||||
If ($RecordsToExport) { $RecordsToExport | Export-Csv "D:\OneDrive - State of North Dakota\RitmExportStorage.csv" -Append -NoTypeInformation -Force }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user