Samples/ImportCallhomeDetails/InFile/processData.ps1
# ------------------------------------------------------------------ # Lenovo Copyright # # (C) Copyright Lenovo 2024 - present. # # LIMITED AND RESTRICTED RIGHTS NOTICE: # If data or software is delivered pursuant a General Services # Administration (GSA) contract, use, reproduction, or disclosure # is subject to restrictions set forth in Contract No. GS-35F-05925. # ------------------------------------------------------------------ . $PSScriptRoot\readInFile.ps1 . $PSScriptRoot\device.ps1 . $PSScriptRoot\countries.ps1 function ProcessData() { param ( [Parameter(Mandatory = $true)] [string] $InFile, [AllowEmptyCollection()] [Parameter(Mandatory = $true)] [hashtable] $OutAddressList, [AllowEmptyCollection()] [Parameter(Mandatory = $true)] [hashtable] $OutDeviceList, [Parameter()] [string] $Path ) $fileContent = ReadContent -File $InFile [hashtable] $unsupportedCountries = @{} [hashtable] $invalidAddresses = @{} $jsonContent = GetCountriesList <# for each device found in provided file - generate the address according with the record in file, - verify if address is in allowed countries for call home operations - verify if address is valid #> foreach ($device in $fileContent) { $addr = [DeviceAddress]::new() $addr.city = $device.City $addr.streetAddress = $device.Street $addr.stateProvince = $device.'State / Province' $addr.countryName = $device.Country $addr.postalCode = $device.'Zip / Postal Code' $addr.fullName = $device.HelpDesk $addr.contactEmail = $device.Email $addr.contactPhone = $device.'Phone# ' $cName = $addr.countryName if ($false -eq [System.String]::IsNullOrWhiteSpace($cName)) { $addr.country = GetCountryAbreviation -Name $cName -CountiesList $jsonContent } $hash = $addr.GetAddressHash() # check country if ((-not [System.String]::IsNullOrWhiteSpace($addr.countryName)) -and [System.String]::IsNullOrWhiteSpace($addr.country)) { if (-not $unsupportedCountries.ContainsKey($hash)) { $unsupportedCountries[$hash] = @{address=$addr; count=0} } $unsupportedCountries[$hash]["count"]++ continue } # check address elseif (-not $addr.IsValid()) { if (-not $invalidAddresses.ContainsKey($hash)) { $invalidAddresses[$hash] = @{address=$addr; count=0} } $invalidAddresses[$hash]["count"]++ continue } else { # add the address to device $OutAddressList[$hash] = $addr $dev = [Device]::new() $dev.addressHash = $hash $dev.serialNumber = $device.'Serial number' $dev.serverName = $device.Name $OutDeviceList[$dev.serialNumber] = $dev } } # save unusable devices .... if ($true -eq [System.String]::IsNullOrWhiteSpace($Path)) { $Path = "$PSScriptRoot\.." | Resolve-Path Write-Host $Path } # Uncomment NoClobber if you dont want to overwrite files for invalid and unsupported addreses. Out-File -FilePath "$Path\_invalidAddresses.json" -Encoding utf8 -InputObject (ConvertTo-Json -InputObject $invalidAddresses -Depth 2) # -NoClobber Out-File -FilePath "$Path\_unsupportedAddresses.json" -Encoding utf8 -InputObject (ConvertTo-Json -InputObject $unsupportedCountries -Depth 2) # -NoClobber } # EOF |