I always love to try new things, so what I have written today is something I love to do; make my life easier and also use my experience to help my colleagues.
With the help of this script I have certainly done that 😉
You can off course change the script to whatever you want to. Sometimes you want to generate an export of an username and export it to a html, csv file or just display it on the screen.
# Written with love by Michel Cheret on 5th August 2020 #
import-module activedirectory
clear-host
$Header = @"
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto')
</style>
<style>
BODY {background-color:white; font-family: 'Roboto', sans-serif;}
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #00cc00;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$username = Read-Host "Please Enter an Username"
$outfilehtml = "C:\temp\$username.html"
$outfilecsv = "C:\temp\$username.csv"
$data = Get-ADPrincipalGroupMembership $username |
Get-ADGroup -Properties * |
Select-Object -Property Name, GroupScope, GroupCategory, Description |
Sort-Object Name
$data2 = $data | Out-String
Write-Output ($Username + ' belongs to the following AD Groups: ' + $data2)
$response = Read-Host 'Would you like export this into CSV (E), HTML (H) or wish to Exit (X)'
switch($response){
E {$data | Export-Csv $outfilecsv -Force -Verbose
Read-Host "CSV File was written to $outfilecsv, press a key to close"}
H {$data | ConvertTo-Html -Property Name, Groupscope, GroupCategory, Description -Head $Header | out-file $outfilehtml
Read-Host "HTML File was written to $outfilehtml, press a key to close"}
X {Write-Information 'Press a key to close'}
}
Have fun 🙂
About me
I am Michel Cheret and I am an driven and enthusiastic IT Guy. I'm working for about 13 years in IT and having done all sorts of things and never experienced a dull moment. I love to learn and develop myself. If you have any questions, please don't hesitate to contact me at michel@michelcheret.com
Â