1)_.Run Function to get CSV file -GUI lets administrators
locate the CSV file
|
Function Import-CSVfile($inDir) { [System.Reflection.Assembly]::LoadWithPartialName('System.windows.forms') |
Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = $inDir $OpenFileDialog.filter = 'All files (*.*)|
*.*' $OpenFileDialog.ShowDialog() | Out-Null $OpenFileDialog.filename $inDir = 'C:\Temp\Migration_CSV_Files\' } |
#(2)_.Import CSV file
|
$csvfile
= Import-CSVfile -initialDirectory $inDir
$UsersArray = Import-Csv -path $csvfile
-ErrorAction Stop |
#(3)_.Validate CSV Header value, expected header from CSV file
is, in this example $header = 'sAMAccountName'
|
$varInf = 'sAMAccountName' if (!($header -like $varInf)
){ Write-Host
'Header DOES NOT have correct value' -ForegroundColor Red Write-Host
'Script will STOP' Start-Sleep
-Seconds 5 break; } |
#(4)_.Same task, Validate CSV header stop script if expected
header is not found
|
$header = $UsersArray[0].psobject.Properties.Name $varInf = 'sAMAccountName' if ($header -like $varInf ){ Write-Host 'Header has correct value' -ForegroundColor Green }else{ Write-Host 'Header DOES NOT have correct value' -ForegroundColor Red } |
Azure Solutions Architect
AWS Certified Cloud Practitioner
Azure Certified Security Engineer Associate
https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
No comments:
Post a Comment