Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. Add-Type -AssemblyNAme System.Windows.Forms
  2. [System.Windows.Forms.Application]::EnableVisualStyles()
  3.  
  4. #Declare Functions
  5.  
  6. function login {
  7. $LiveCred = Get-Credential
  8. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
  9. Import-PSSession $Session
  10. $btnlogin.Visible = $False
  11. }
  12. function quitprogram {
  13. $Form.Close()
  14. Exit-PSSession []
  15. }
  16.  
  17. function CalendarShare {
  18. Add-MailboxFolderPermission -Identity ${FromUser.Text} -AccessRights Editor -User ${ToUser.Text}
  19. }
  20.  
  21. #Creates base form
  22. $Form = New-Object system.Windows.Forms.Form
  23. $Form.ClientSize = '400,400'
  24. $Form.Text = 'Powershell GUI'
  25. $Form.TopMost = $False
  26.  
  27. #Creates Login button
  28. $btnlogin = New-Object System.windows.Forms.button
  29. $btnlogin.text = 'Login'
  30. $btnlogin.width = 80
  31. $btnlogin.height = 40
  32. $btnlogin.location = New-Object System.Drawing.Point(150,5)
  33. #Add_Click defines what to do on click
  34. $btnlogin.Add_Click( {
  35. login #function previously defined. Line 6
  36. })
  37.  
  38. #Creates label for From user
  39. $FromUserLabel = New-Object system.Windows.Forms.Label
  40. $FromUserLabel.text = 'Share Calendar From User'
  41. $FromUserLabel.AutoSize = $true
  42. $FromUserLabel.width = 25
  43. $FromUserLabel.height = 10
  44. $FromUserLabel.location = New-Object System.Drawing.Point(130,100) #Define where it appears on the map
  45.  
  46. #Create first input. From User
  47. $FromUser = New-Object system.Windows.Forms.TextBox
  48. $FromUser.multiline = $False
  49. $FromUser.width - 200
  50. $FromUser.height = 20
  51. $FromUser.location = New-Object System.Drawing.Point(135,125)
  52.  
  53. #Create label for To user
  54. $ToUserLabel = New-Object system.Windows.Forms.Label
  55. $ToUserLabel.text = 'Share Calendar To User'
  56. $ToUserLabel.AutoSize = $True
  57. $ToUserLabel.width = 25
  58. $ToUserLabel.height = 10
  59. $ToUserLabel.location = New-Object System.Drawing.Point(135,175)
  60.  
  61. #Create second input. To User
  62. $ToUser = New-Object system.Windows.Forms.TextBox
  63. $ToUser.multiline = $False
  64. $ToUser.width - 200
  65. $ToUser.height = 20
  66. $ToUser.location = New-Object System.Drawing.Point(135,200)
  67.  
  68. #Create Share Button Calendar
  69. $btnsharecalendar = New-Object System.windows.Forms.button
  70. $btnsharecalendar.text = 'Share Calendar'
  71. $btnsharecalendar.width = 165
  72. $btnsharecalendar.height = 30
  73. $btnsharecalendar.location = New-Object System.Drawing.Point(105,275)
  74. #Define Add_Click below
  75. $btnsharecalendar.Add_Click({
  76. CalendarShare
  77. })
  78.  
  79.  
  80.  
  81. #Create button to close program
  82. $btnquit = New-Object System.windows.Forms.button
  83. $btnquit.text = 'Quit'
  84. $btnquit.width = 80
  85. $btnquit.height = 40
  86. $btnquit.location = New-Object System.Drawing.Point(150,325)
  87. #Add_Click defines what to do on click
  88. $btnquit.Add_Click( {
  89. quitprogram #function previously defined. Line 12
  90. })
  91.  
  92.  
  93. #Allows form to work
  94. $Form.Controls.AddRange(@($btnlogin,$FromUserLabel,$FromUser,$ToUserLabel,$ToUser,$btnsharecalendar,$btnquit))
  95. $Form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement