en:powershell:start
This is an old revision of the document!
PowerShell
Basics
According to me, the first thing we need to deal with is CSV file. First let's read one CSV file, loop over it.
Here is an example of CSV input file.
Samaccountname | |
---|---|
abc123 | abc123@domain.com |
def123 | def123@domain.com |
ghi123 | ghi123@test.com |
- input.csv
Samaccountname,Mail abc123,abc123@domain.com def123,def123@domain.com ghi123,ghi123@test.com
- csvLevel1.ps1
Import-Csv -Path input.csv | foreach { # save current object into different variable $currentLine = $_ # deal with columns $mail = $currentLine.Mail # test domain mail # we add a property with the result of our test if ($mail -match "domain.com$") { $currentLine | Add-Member -MemberType NoteProperty -Name "domainCheck" -Value "valid" } else { $currentLine | Add-Member -MemberType NoteProperty -Name "domainCheck" -Value "invalid" } # return updated currentLine with new column $currentLine } | # export result line by line to CSV # -NoTypeInformation prevents metadata from being exported Export-Csv -Path preCheck.csv -NoTypeInformation
en/powershell/start.1615347286.txt.gz · Last modified: 2021/03/09 22:34 by lonclegr