Content

Views and Opinions of a IT Pro specializing in Infrastructure Technologies | VMware, Exchange, Windows, SANs (EqualLogic / NetApp), Microsoft | CCNA, MCITP

Set Calendar Permissions v2

Wednesday 13 April 2011 - Filed under Exchange + Powershell

I was recently requested to add “Reviewer” rights for a specific user on every calendar hosted on my Exchange 2010 SP1 environment. Looking to automate the process I started looking around for a way to complete this task via PowerShell.

I came across a script written by Jan Egil Ring that adds “Reviewer” permissions for the “Default” user on all mailboxes queried. Using this script as a guideline I wrote a dynamic script that would allow me to set any permission for any user to all mailboxes by simply passing specific variables to the script.

Example Run:
(Give CalendarView group ‘Owner’ rights on all calendars)
“c:\scripts\Set-CalendarPermissions-v2.ps1 CalendarView Owner”

I run this script daily as a scheduled task so I added some Write-Output commands to allow the on-screen Write-Host outputs to be piped to a text file by using the >c:\output.txt after the command.

param([string]$AccessUser,[string]$AccessRights)

#NAME: Set-CalendarPermissions-v2.ps1
#ORIGINAL AUTHOR: 	Jan Egil Ring
#ORIGINAL COMMENT: 	Script to set calendar-permission for mailboxes in Exchange Server 2010. #More information: http://blog.powershell.no/2010/09/20/managing-calendar-permissions-in-exchange-server-2010
#COMMENT: 	Run as .\Set-CalendarPermissions-v2.ps1 [USERNAME/GROUP] [PERMISSION]
#You must set a username, however if you leave out the permission parameter the script will default to 'Reviewer'
#LAST UPDATED: 4/13/2011 10:56PM

Write-Host "Starting Script Set-CalendarPermissions.ps1"
Write-Output "Starting Script Set-CalendarPermissions.ps1"

IF (!$AccessUser){
Write-Host ""
Write-Output ""
Write-Host "AccessUser Parameter has not been set..." -ForegroundColor Red
Write-Output "AccessUser Parameter has not been set..."
Write-Host "Run as '.\Set-CalendarPermissions-v2.ps1 CalendarView" -ForegroundColor White
Write-Output "Run as '.\Set-CalendarPermissions-v2.ps1 CalendarView"
Write-Host ""
exit
}

Write-Host "AccessRight Set to $AccessUser"
Write-Output "AccessRight Set to $AccessUser"

IF (!$AccessRights){
$AccessRights = "Reviewer"
}

Write-Host "AccessRight Set to $AccessRights"
Write-Output "AccessRight Set to $AccessRights"

#requires -version 2

#Load Exchange Server 2010 Management Shell if not loaded. You may delete/comment out this step if you are running the script from the Exchange Management Shell
if (-not (Get-PSSnapin | Where-Object {$_.Name -like "Microsoft.Exchange.Management.PowerShell.E2010"})){
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}

#Custom variables
$mailboxes = Get-Mailbox

#Loop through all mailboxes
foreach ($mailbox in $mailboxes) {

#Retrieve name of the user`s calendar
$calendar = (($mailbox.SamAccountName)+ ":\" + (Get-MailboxFolderStatistics -Identity $mailbox.SamAccountName -FolderScope Calendar | Select-Object -First 1).Name)

#Check if calendar-permission for user "AccessUser"
if (-not ((Get-MailboxFolderPermission $calendar  | Where-Object {$_.User -like $AccessUser}))) {

Write-Host "Updating calendar permission for $mailbox..." -ForegroundColor Yellow
Write-Output "Updating calendar permission for $mailbox..."

Add-MailboxFolderPermission -User $AccessUser -AccessRights $AccessRights -Identity $calendar
}

#Check if calendar-permission for user "AccessUser" is set to the default permission of "Reviewer"
if (((Get-MailboxFolderPermission $calendar  | Where-Object {$_.User -like $AccessUser}).AccessRights) -notlike "Reviewer" ) {

Write-Host "Updating calendar permission for $mailbox..." -ForegroundColor Yellow
Write-Output "Updating calendar permission for $mailbox..."

#Set calendar-permission for user "Default" to value defined in variable $AccessRights
Set-MailboxFolderPermission -User $AccessUser -AccessRights $AccessRights -Identity $calendar
}
}

You can download a copy of this script here: Set-CalendarPermissions-v2.ps1

1 comment  ::  Share or discuss  ::  2011-04-13  ::  Kevin

Query ESX Hostname from VM using PowerCLI & vmtoolsd

Thursday 10 March 2011 - Filed under VMware

One of the engineers at work pointed me to a post by @lamw in his blog article “How To Extract Host Information From Within a VM” in the article @lamw talks about creating dynamic variables on a VM that can be queried via vmtoolsd command inside the VM itself.

This is a very cool idea however it focuses on how to make it work on ESX w/a Service Console  or the vMA where you can setup cron jobs and run Perl scripts.

The main reason the engineer asked me to look into this is our current Monitoring system has no way of knowing what machines are on any given host. By providing a way for a guest based poller to discover the underling host we get two value adds:

- This allows us to write logic to pause alerts for all VMs when a host goes offline (avoiding the 50k in spam messages when all alerts fire for 30 VMs)
- Help us correlate performance issues / general errors on one VM to another VM’s CPU/MEM usage  or simply a  ESX host issue.

After reading how @lamw implemented his solution I realized I had two issues

1) I’m not a comfortable with Perl so modifying his examples were going to be difficult
2) All of my VMware hosts are ESXi so running anything in a cron tab is not an option

I’m not a Linux guy so I decided to look into a different way to solve the same problem. I’ve been reading ton of scripting examples on PowerCLI so I decided to see if I could find a way to do this using PowerShell.

After going over PowerShell examples from @alanrenouf over athttp://www.virtu-al.net/ I decided to try to write a PowerCLI script that I could run via a Windows Scheduled Task.

(more…)

2 comments  ::  Share or discuss  ::  2011-03-10  ::  Kevin

Veeam Backup: Unable to access file unspecified filename since it is locked

Sunday 5 December 2010 - Filed under Veeam + VMware

Over the past week I’ve been troubleshooting a Veeam Backup & Replication issue where drives that are HOTADDed to my Veeam server (Application Mode) where drives are not removed after a backup causing issues when I attempt to delete Snapshots via the vSphere Client. While backups were sometimes successful I continually have to clear drives from my utility server that fail to remove after a backup completes

Unable to access file <unspecified filename> since it is locked Veeam Backup will attempt to remove snapshot during the next job cycle, but you may consider  removing snapshot manually.

(more…)

1 comment  ::  Share or discuss  ::  2010-12-05  ::  Kevin

Get Adobe Flash playerPlugin by wpburn.com wordpress themes