Skip to content

Instantly share code, notes, and snippets.

@jhochwald
Created March 25, 2016 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhochwald/c44224732db9fb2782fb to your computer and use it in GitHub Desktop.
Save jhochwald/c44224732db9fb2782fb to your computer and use it in GitHub Desktop.
Show the Permission set on the Users Calendar via PowerShell
#region License
<#
{
"info": {
"Statement": "Code is poetry",
"Author": "Joerg Hochwald",
"Contact": "joerg.hochwald@outlook.com",
"Link": "http://hochwald.net",
"Support": "https://github.com/jhochwald/MyPowerShellStuff/issues"
},
"Copyright": "(c) 2012-2016 by Joerg Hochwald & Associates. All rights reserved."
}
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
By using the Software, you agree to the License, Terms and Conditions above!
#################################################
# modified by : Joerg Hochwald
# last modified : 2016-03-25
#################################################
#>
#endregion License
Function Global:Get-CalendarPermission {
<#
.SYNOPSIS
Show the Permission set on the Users Calendar
.DESCRIPTION
Show the Permission set on the Users Calendar
.PARAMETER User
User name or UPN
.PARAMETER Cloud
Apply to Exchange Online
.EXAMPLE
PS C:\> Get-CalendarPermission -User 'John.Doe'
RunspaceId : a8ccfa99-b28b-4427-8c19-5991efed413b
Identity : John.doe:\Calendar
FolderName : Calendar
User : Default
AccessRights : {AvailabilityOnly}
IsValid : True
ObjectState : New
RunspaceId : a8ccfa99-b28b-4427-8c19-5991efed413b
Identity : John.doe:\Calendar
FolderName : Calendar
User : Anonymous
AccessRights : {None}
IsValid : True
ObjectState : New
RunspaceId : a8ccfa99-b28b-4427-8c19-5991efed413b
Identity : John.doe:\Calendar
FolderName : Calendar
User : ExchangePublishedUser.Jane.Doe@contoso.com
AccessRights : {AvailabilityOnly}
IsValid : True
ObjectState : New
Perform the search against an on Premises user
.EXAMPLE
PS C:\> Get-CalendarPermission -User 'John.Doe' -Cloud
RunspaceId : a8ccfa99-b28b-4427-8c19-5991efed413b
Identity : John.doe:\Calendar
FolderName : Calendar
User : Default
AccessRights : {AvailabilityOnly}
IsValid : True
ObjectState : New
RunspaceId : a8ccfa99-b28b-4427-8c19-5991efed413b
Identity : John.doe:\Calendar
FolderName : Calendar
User : Anonymous
AccessRights : {None}
IsValid : True
ObjectState : New
RunspaceId : a8ccfa99-b28b-4427-8c19-5991efed413b
Identity : John.doe:\Calendar
FolderName : Calendar
User : ExchangePublishedUser.Jane.Doe@contoso.com
AccessRights : {AvailabilityOnly}
IsValid : True
ObjectState : New
Perform the search against an on Exchange Online user
.EXAMPLE
[Office365] PS C:\> Get-CalendarPermission -User "John.Doe" -WhatIf
What if: Performing the operation "Get Calendar permission" on target "User Obejct John.Doe@contoso.com".
Dry Run for the Command, show what will happen but do NOTHING!
.NOTES
Hybrid Command: Works for on Premises, Exchange Online and hybrid instances
#>
[CmdletBinding(ConfirmImpact = 'None',
SupportsShouldProcess = $true)]
param
(
[Parameter(ValueFromPipeline = $true,
Position = 0,
HelpMessage = 'User name or UPN')]
[ValidateNotNullOrEmpty()]
[Alias('UPN')]
[System.String]$User,
[Parameter(Position = 1,
HelpMessage = 'Apply to Exchange Online')]
[switch]$Cloud
)
BEGIN {
if (-not ($user -like "*@$localDomain")) {
$user = ($user + "@" + $localDomain)
}
}
PROCESS {
if ($pscmdlet.ShouldProcess("User Obejct $User", "Get Calendar permission")) {
try {
if ($Cloud) {
$CalendarFolder = ((Get-CloudMailboxFolderStatistics $user | Where { ($_.FolderType -eq "Calendar") }).FolderPath.Replace("/", "\"))
} else {
$CalendarFolder = ((Get-MailboxFolderStatistics $user | Where { ($_.FolderType -eq "Calendar") }).FolderPath.Replace("/", "\"))
}
$UserString = ($user + ':' + $CalendarFolder)
if ($Cloud) {
$CalendarPermission = (Get-CloudMailboxFolderPermission $UserString -ErrorAction:Stop -WarningAction:SilentlyContinue)
} else {
$CalendarPermission = (Get-MailboxFolderPermission $UserString -ErrorAction:Stop -WarningAction:SilentlyContinue)
}
} catch [System.Exception] {
Write-Error -Message "Error: $($_.Exception.Message) - Line Number: $($_.InvocationInfo.ScriptLineNumber)" -ErrorAction Stop
# Aw Snap! We are still here? Fix that the Bruce Willis way: DIE HARD!
exit 1
} catch {
Write-Error -Message "Unable to search for $user" -ErrorAction Stop
# Still here? Make sure we are done!
break
# Aw Snap! We are still here? Fix that the Bruce Willis way: DIE HARD!
exit 1
}
}
}
END {
if ($CalendarPermission) {
Return $CalendarPermission
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment