Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 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)}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement