Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. ## import the ImportExcel PowerShell module, for dealing with an Excel file from PowerShell (install first if not already there)
  2. Find-Module ImportExcel | Install-Module
  3. Import-Module ImportExcel
  4.  
  5.  
  6.  
  7. ## for reals: export, per user, a new XLSX file with just their info in it
  8. Import-Excel C:\temp\XlsxAndAutomation\userinfo.xlsx | Foreach-Object {Export-Excel -Path "C:\temp\XlsxAndAutomation\daterForUsers\$($_.user).xlsx" -InputObject $_ -Password ($_.xlsxFilePassword) -AutoSize}
  9. ## can we open one? What's in it?
  10. Invoke-Item C:\temp\XlsxAndAutomation\daterForUsers\user19118.xlsx
  11.  
  12. ## 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
  13. ## essentially this syntax -- we need to tighten it up on Send-MailMessage -- this is the gist!
  14. Import-Excel C:\temp\XlsxAndAutomation\userinfo.xlsx | Foreach-Object {
  15. 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
  16. 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
  17. }
  18.  
  19. ## or, make files by supervisor (just using supervisor's email's name portion for the file name)
  20. 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}
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. ## need some new passwords? Heeump! (Windows PowerShell only, not PowerShell Core)
  30. Add-Type -AssemblyName System.Web
  31. ## make 500 new passwords of length 23 chars with at least three non-alphanum chars
  32. 1..500 | Foreach-Object {[System.Web.Security.Membership]::GeneratePassword(23, 3)}
  33.  
  34. ## Oh, need one for e'ery user up in this btch?!
  35. 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