Created
September 5, 2019 01:08
-
-
Save mtboren/411650982780b76e5940ce4d37d18953 to your computer and use it in GitHub Desktop.
Some Examples of Data Manipulation and Password Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## import the ImportExcel PowerShell module, for dealing with an Excel file from PowerShell (install first if not already there) | |
Find-Module ImportExcel | Install-Module | |
Import-Module ImportExcel | |
## for reals: export, per user, a new XLSX file with just their info in it | |
Import-Excel C:\temp\XlsxAndAutomation\userinfo.xlsx | Foreach-Object {Export-Excel -Path "C:\temp\XlsxAndAutomation\daterForUsers\$($_.user).xlsx" -InputObject $_ -Password ($_.xlsxFilePassword) -AutoSize} | |
## can we open one? What's in it? | |
Invoke-Item C:\temp\XlsxAndAutomation\daterForUsers\user19118.xlsx | |
## then, send a couple of emails to each user: one w/ the password-protected XLSX file w/ their new acct info in it, one that is just the password to their XLSX file | |
## essentially this syntax -- we need to tighten it up on Send-MailMessage -- this is the gist! | |
Import-Excel C:\temp\XlsxAndAutomation\userinfo.xlsx | Foreach-Object { | |
Send-MailMessage -Attachments C:\temp\XlsxAndAutomation\daterForUsers\$($_.user).xlsx -From matt@mail.com -SmtpServer server@dom.com -Body "Here's your stuff, buddy (attached) -- separate email coming w/ other info" -Cc $_.supervisorEmail -BodyAsHtml -Subject "some creds or something" -To $_.emailAddress -whatif | |
Send-MailMessage -From matt@mail.com -SmtpServer server@dom.com -Body "use this for your XLSX: $($_.xlsxFilePassword)" -Cc $_.supervisorEmail -BodyAsHtml -Subject "other" -To $_.emailAddress -whatif | |
} | |
## or, make files by supervisor (just using supervisor's email's name portion for the file name) | |
Import-Excel C:\temp\XlsxAndAutomation\userinfo.xlsx | Group-Object -Property supervisorEmail | ForEach-Object {Export-Excel -Path C:\temp\XlsxAndAutomation\daterForUsers\$($_.Group[0].supervisorEmail.Split("@")[0]).xlsx -Password $_.Group[0].xlsxFilePassword -InputObject $_.Group -AutoSize} | |
## need some new passwords? Heeump! (Windows PowerShell only, not PowerShell Core) | |
Add-Type -AssemblyName System.Web | |
## make 500 new passwords of length 23 chars with at least three non-alphanum chars | |
1..500 | Foreach-Object {[System.Web.Security.Membership]::GeneratePassword(23, 3)} | |
## Oh, need one for e'ery user up in this btch?! | |
Import-Excel C:\temp\XlsxAndAutomation\userinfo.xlsx | Select-Object -Property *, @{n="NewPasswdForSomething"; e={[System.Web.Security.Membership]::GeneratePassword(23, 3)}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment