en:powershell:advanced
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:powershell:advanced [2021/03/15 21:18] – [Advanced] lonclegr | en:powershell:advanced [2021/03/16 21:51] (current) – lonclegr | ||
---|---|---|---|
Line 9: | Line 9: | ||
- | Now let's discover how to query one Active Directory. First one new PowerShell module is required to deal with AD. | + | Now let's discover how to query one Active Directory. First a new PowerShell module is required to deal with AD. |
<code powershell> | <code powershell> | ||
Line 32: | Line 32: | ||
</ | </ | ||
- | Before | + | Previously |
<file powershell csvLevel2.ps1> | <file powershell csvLevel2.ps1> | ||
Line 39: | Line 39: | ||
Import-Csv -Path input.csv | foreach { | Import-Csv -Path input.csv | foreach { | ||
- | # save current object into different | + | # save current object into a local variable |
$currentLine = $_ | $currentLine = $_ | ||
- | # deal with columns | + | # retrieve |
$mail = $currentLine.Mail | $mail = $currentLine.Mail | ||
$sam = $currentLine.Samaccountname | $sam = $currentLine.Samaccountname | ||
Line 73: | Line 73: | ||
Write-Verbose ("No AD active user found with SAM={0}" | Write-Verbose ("No AD active user found with SAM={0}" | ||
$currentLine | Add-Member -MemberType NoteProperty -Name " | $currentLine | Add-Member -MemberType NoteProperty -Name " | ||
+ | $currentLine | Add-Member -MemberType NoteProperty -Name " | ||
} | } | ||
Line 80: | Line 81: | ||
# export result line by line to CSV | # export result line by line to CSV | ||
# -NoTypeInformation prevents metadata from being exported | # -NoTypeInformation prevents metadata from being exported | ||
- | # -Encoding is specified because | + | # -Encoding is specified because we are querying AD (UTF-8) |
Export-Csv -Path preCheck.csv -NoTypeInformation -Encoding UTF-8 | Export-Csv -Path preCheck.csv -NoTypeInformation -Encoding UTF-8 | ||
</ | </ | ||
+ | |||
+ | This script will output CSV file with two new columns. | ||
+ | |||
+ | <file csv preCheck.csv> | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | <csv> | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | </ |
en/powershell/advanced.1615857504.txt.gz · Last modified: by lonclegr