Share_Calendar.ps1


<#PSScriptInfo
 
.VERSION 0.1.1.3
 
.GUID a44b9e13-8826-4334-98da-5c5a73613a8e
 
.AUTHOR Oliver Perring
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Calendar Permissions GUI
 
#>
 

Param()


Write-Output "Enter the 365 Admin Details into the pop up"

$PSExoPowershellModuleRoot = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select -Last 1).DirectoryName
$ExoPowershellModule = "Microsoft.Exchange.Management.ExoPowershellModule.dll";
$ModulePath = [System.IO.Path]::Combine($PSExoPowershellModuleRoot, $ExoPowershellModule);

 

Import-Module $ModulePath;

 

$Office365PSSession = New-ExoPSSession -ConnectionUri "https://outlook.office365.com/powershell-liveid/"

 

Import-PSSession $Office365PSSession

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$ShareCalendar                   = New-Object system.Windows.Forms.Form
$ShareCalendar.ClientSize        = '249,187'
$ShareCalendar.text              = "Share Calendar"
$ShareCalendar.TopMost           = $false

$UserToShare                     = New-Object system.Windows.Forms.TextBox
$UserToShare.multiline           = $false
$UserToShare.width               = 230
$UserToShare.height              = 20
$UserToShare.location            = New-Object System.Drawing.Point(17,45)
$UserToShare.Font                = 'Microsoft Sans Serif,10'

$UserToSee                       = New-Object system.Windows.Forms.TextBox
$UserToSee.multiline             = $false
$UserToSee.width                 = 231
$UserToSee.height                = 20
$UserToSee.location              = New-Object System.Drawing.Point(17,98)
$UserToSee.Font                  = 'Microsoft Sans Serif,10'

$btnSave                         = New-Object system.Windows.Forms.Button
$btnSave.text                    = "Save"
$btnSave.width                   = 60
$btnSave.height                  = 30
$btnSave.location                = New-Object System.Drawing.Point(19,132)
$btnSave.Font                    = 'Microsoft Sans Serif,10'

$Label1                          = New-Object system.Windows.Forms.Label
$Label1.text                     = "User to see Calendar"
$Label1.AutoSize                 = $true
$Label1.width                    = 25
$Label1.height                   = 10
$Label1.location                 = New-Object System.Drawing.Point(20,76)
$Label1.Font                     = 'Microsoft Sans Serif,10'

$Label2                          = New-Object system.Windows.Forms.Label
$Label2.text                     = ""
$Label2.AutoSize                 = $true
$Label2.width                    = 25
$Label2.height                   = 10
$Label2.location                 = New-Object System.Drawing.Point(40,-11)
$Label2.Font                     = 'Microsoft Sans Serif,10'

$Label3                          = New-Object system.Windows.Forms.Label
$Label3.text                     = "User to share Calendar"
$Label3.AutoSize                 = $true
$Label3.width                    = 25
$Label3.height                   = 10
$Label3.location                 = New-Object System.Drawing.Point(19,20)
$Label3.Font                     = 'Microsoft Sans Serif,10'

$ShareCalendar.controls.AddRange(@($UserToShare,$UserToSee,$btnSave,$Label1,$Label2,$Label3))

$btnSave.Add_Click({ 
$CalendarUser = $UserToShare.text
$CalendarUserCAL = $CalendarUser + ":\calendar"
Add-MailboxFolderPermission -Identity $CalendarUserCAL -user $UserToSee.text -AccessRights Editor
Set-MailboxFolderPermission -Identity $CalendarUserCAL -user $UserToSee.text -AccessRights Editor
})

[void]$ShareCalendar.ShowDialog()