Replace-RequestAccessEmail

Retrieve and update/change access request on all the sites/webs inside a web application that has my email as the access request. Some sites have a branch site managers email group that need to be used as well. Sourced from PowerShell script to update Access Request Email Address for multiple sites and webs and Windows PowerShell: Build a Better Function.

function Replace-RequestAccessEmail {
<#
.SYNOPSIS
Update Access Request containing Specified Email
.DESCRIPTION
Find all the Access Request Settings that have a specified email and replace it with either another account, another account and the Branch Site Managers email, or remove from string
.EXAMPLE
Replace the email address with a new address and the Branch Site Managers email
Replace-RequestAccessEmail -webapp "https://WEBAPP1" -email "Joe.Cool@email" -replace "SPADMIN@email" -SPSiteMgrs
.EXAMPLE
Removes the email address from the string
Replace-RequestAccessEmail -webapp "https://WEBAPP1" -email "Joe.Cool@email"
.PARAMETER webapp
Web Application to cycle through.
.PARAMETER email
Email in Access Request Setting to locate
.PARAMETER replace
(OPTIONAL) Email to use as replacement - leave off to have email removed from string.
.PARAMETER SPSiteMgrs
(OPTIONAL) Include to replace using Site Managers email based on Site Collection
#>
[CmdletBinding()]
param
(
[Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]$webapp,
[string]$email,
[string]$replace,
[switch]$SPSiteMgrs
)
process {
$webapplication = Get-SPWebApplication -Identity $webapp
[string]$trimSites = $webapplication.URL
$trimSites = $trimSites + "sites/"
foreach($site in $webapplication.Sites)
{
foreach($web in $site.AllWebs)
{
if ($web.HasUniquePerm -and $web.RequestAccessEnabled)
{
if ($web.RequestAccessEmail -like "*$email*")
{
$siteCollection = $web.Site | %{$_.URL}
$siteCollection = $siteCollection.TrimStart($trimSites)
Write-Host "Site Collection: " $siteCollection
Write-Host "On Web" $web.Title ", URL" $web.URL
Write-Host "`tAccess requests go to :" $web.RequestAccessEmail
If($SPSiteMgrs.IsPresent)
{
If(!$replace.IsPresent)
{
#Default with Admin Account
$replace = "SPADMIN@EMAIL"
}
switch ($siteCollection)
{
"BRANCH_A" {$requestAccessEmail = "$replace; BRANCH_A.SPSiteMgr@EMAIL"}
"BRANCH_B" {$requestAccessEmail = "$replace; BRANCH_B.SPSiteMgr@EMAIL"}
"BRANCH_C" {$requestAccessEmail = "$replace; BRANCH_C.SPSiteMgr@EMAIL"}
default {$requestAccessEmail = "$replace"}
}
} else
{
$requestAccessEmail = $web.RequestAccessEmail
$reqeustAccessEmail = $requestAccessEmail.ToLower()
$email = $email.ToLower()
$requestAccessEmail = $requestAccessEmail.Replace($email,$replace)
}
# If the Request Access Email would be blank, set to SharePoint Admins Email
If ($requestAccessEmail -eq "")
{
$requestAccessEmail = "SPADMIN@EMAIL"
}
Write-Host "`t***Will Update Request Access Email to: "$requestAccessEmail "***"
$web.RequestAccessEmail = $requestAccessEmail
$web.Update()
}
}
} #end ForEachWeb
#Dispose of the site object
$site.Dispose()
} #end ForEachSite
} #end Process
} #endFunction
Advertisements

No two choices should have the same ID

Add from existing site columns results in error. Looking up the Correlation ID in the ULS Logs gave a clue of “System.ArgumentException: No two choices should have the same ID.” You know, Microsoft, it would help to know what ID that was. But I guess that would deny me the fun of looking for it. I tried the advice given by Lars Lynch, but the SharePoint Manager didn’t allow me to sort the field’s information, so didn’t really help me.

Using PowerShell, I got a listing of all the fields, their ID’s and their Internal Names:

$web = Get-SPWeb https://webapp/sites/SITE/WEB 
foreach ($field in $web.Fields){ 
 write-output "$($field.Group) | $($field.Title) | $($field.Id) | $($field.InternalName)" 
}
$web.Dispose() 

This gave me a list I could sort in excel (after some manipulation) to try and find duplicates. Unfortunately that didn’t work. So I starting comparing the list it gave me to the one on the site columns page (_layouts/mngfield.aspx).

There I discovered a field listed twice on the site columns page, but only once in my list (note: the list output shown is the unsorted view):

After ensuring the field wasn’t used anywhere, I modified my script to remove the field:

$findGUID = "75af1e7d-ad81-4566-9edd-a582b2a7de13" 
$web = Get-SPWeb https://webapp/sites/SITE/WEB 
foreach ($field in $web.Fields){ 
 if($field.Id -eq $findGUID){
 write-output "$($field.Group) | $($field.Title) | $($field.Id) | $($field.InternalName)"
 $field.Allowdeletion = $true
 $field.Sealed = $false
 $field.Delete()
 Break
 }
}
$web.Dispose() 

The two instances of the field were removed from the site and I was able to “Add from existing site columns” again without error.

Update Permission Set

I needed to create a script to update two permission sets throughout my farm:

$allWebApps = ("https://WEBAPP1.COM", "https://WEBAPP2.COM")
function fnUpdatePermSet {
    #Get the root Web site of the site collection.
    $web=$site.RootWeb
    # Use the RoleDefinitions property of the SPWeb class to get the collection of role definitions for a Web site. Use an indexer to return a single item from the collection.
    $UpdatePermissionSet=$web.RoleDefinitions[$roleName];
    # Use the BasePermissions property of the SPRoleDefinition class to set the base permissions for a role definition.
    $UpdatePermissionSet.BasePermissions=$rolePerms;
    # Use the Update Method of the SPRoleDefinition class
    $UpdatePermissionSet.Update()
}
foreach ($siteUrl in $allWebApps){
   Write-Host "$siteUrl";
   $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl);
   $spWebApp = $rootSite.WebApplication;
   foreach($SPSite in $spWebApp.Sites){
      #Get site collection
      $site = Get-SPSite $SPSite
      Write-Host $site
      $roleName = "Edit-Add";
      $rolePerms = "ViewListItems,AddListItems,EditListItems,OpenItems,ViewVersions,ViewFormPages,Open,ViewPages,BrowseDirectories,BrowseUserInfo,UseRemoteAPIs,UseClientIntegration,CreateAlerts,ManagePersonalViews";
      fnUpdatePermSet;
      
      $roleName = "Add Only";
      $rolePerms = "ViewListItems,AddListItems,OpenItems,ViewVersions,ViewFormPages,Open,ViewPages,BrowseDirectories,BrowseUserInfo,UseRemoteAPIs,UseClientIntegration,CreateAlerts,ManagePersonalViews";
      fnUpdatePermSet;

      #Dispose of the site object
      $site.Dispose()
   }
$rootSite.Dispose();
}

SharePoint Saturday Louisville

I had a blast at SharePoint Saturday Louisville. If you’ve never gone to a technical user group function, please do. The local ones let you meet your peers and the larger ones, like SharePoint Saturday, let you meet some amazing talent (who are also super nice approachable people as well.) This was the first SharePoint Saturday in Louisville, and hopefully it was enough of a success that they’ll have one next year.

Sessions were 70 minutes long, which isn’t actually a lot of time if your presenter has a pulse and is knowledgeable on their subject. Lucky for me, I never found myself snoozing during a session. What I usually get most out of these sessions is a resource for more information in the future. With one exception, I followed the Administrator / IT Pro track.

First up was “Build your SharePoint Internet Presence with PowerShell” with Ryan Dennis. I’ve been teaching myself PowerShell for use with SharePoint and he showed how me how to couple that knowledge with XML for more automation goodness. I look forward to dissecting and absorbing his code for future use. Unfortunately, I missed his next session on “Funnel your Info down a new Path”, but Ryan is a blogger – so I now have a new resource to follow and he posted all the slides from that session. YAY!

Next was “SharePoint Diagnostics (SPDiag 3.0) in Action” with Tony Maddin. I have to say I was disappointed in this presentation, not because it wasn’t good, it was, it just wasn’t the presentation I wanted it to be. I have recently installed SPDiag and I now have all this data, had it for like a month now, but I really don’t have a clear picture of what to do with it. What’s It All About, Alfie? Tony did a great presentation on introducing the tool, and doing a quick rundown on the reports it generates, but that’s about all he had time for, so didn’t go into any detail about those reports. He did give a good recommendation about capturing a baseline and then generating reports on a regular basis to see what the trends are (and suggested that it could be scheduled with Powershell.) So as my data collects and trends, I’ll hopefully figure out what to do with it. He also mentioned that using Kerberos over NTML would give better performance, something else I need to look into. So while his presentation wasn’t exactly what I, selfishly, wanted it to be, I still have some take-aways on improving my environment.

After Lunch I hopped over to the Information Worker track to see Jason Keller‘s talk on “Building Out of the Box Solutions.” If you’re an admin, you may wonder why attend a session on something you already know how to do. Ah, but do you know how to tell someone else how to do it? I can create a content type, and I can create views, I can do all kinds of stuff, but can I explain it to an end-user so they’re excited about doing it themselves? Um, no; not often anyway. Jason went with the baseball theme of the conference and showed how to create a Baseball Player content type, and then Pitcher and Outfielder child-content types and then views for both. He was very entertaining and I don’t think anyone will forget his session.

Back to the Admin track for CA Callahan‘s “Frugal Admin series: What can you get for nothing? Quite a lot actually…” where I developed an immediate platonic nerd-girl-crush for CA Callahan. She’s quick and funny and knows her stuff. She’s also the author of “Mastering Microsoft SharePoint Foundation 2010.” The 70 minutes wasn’t enough to go through everything she had to cover, but her slides were packed with information to look into afterwards. She mentioned IndiHiang, Webalizer (Tobias Schwarz version), Script Gallery on TechNet and others. She even mentioned more when she emailed me the slides – so be sure to catch one of her sessions if you get the chance.

The last speaker was Stephen Wilson covering “System Reviews: A checkup for SharePoint2010.” Stephen covered a lot of good information and if you go to his blog, you’ll see he’s already posted his slides from Louisville. The most frustrating part of my job is I spend more of my Admin time reacting to things instead of being proactive. As I review my notes from his session and his slides, all I can think is, “you know you should be doing this, and here’s some more that you should be doing as well. Bad Admin – bad!” Hopefully, Stephen will be presenting at SharePoint Saturday Cincinnati as well and I can feel even guiltier.

Update RequestAccessEmail with PowerShell

Update: I have an improved version of this at:  Replace-RequestAccessEmail

I sometimes forget to change the Request Access Email from using my account to the group admin distribution email. This helps correct that:

$webapp = Get-SPWebApplication "https://WEBAPP"
foreach($site in $webapp.Sites){
     foreach($web in $site.AllWebs){
         if ($web.HasUniqueRoleDefinitions){
             if($web.RequestAccessEnabled){
                 Write-Host $Web.URL
                 Write-Host $Web.RequestAccessEmail
                 Write-Host "---"
                 if ($web.RequestAccessEmail -eq 'my.email@email.com'){
                     Write-Host $Web.URL "Update RequestAccessEmail"
                     Write-Host "---"
                     $web.RequestAccessEmail ="SPADMIN.GROUP@email.com"
                     $web.Update()
                 }
             }
             else {
                 Write-Host "Access Request Settings not enabled." $Web.URL
             }
         }
     }
 }

How to find a Sharepoint feature by GUID

This post really helped me out.  I’m trying to deploy a newly “developed” site, put together by developers new to SharePoint, and done more in Designer than in Visual Studio.

How to find a Sharepoint feature by GUID

Term Store Management Missing

Ack!  The “Term store management” is missing from my Site Adminstration section!

Enable-SPFeature -id “73EF14B1-13A9-416b-A9B5-ECECA2B0604C” -Url https://WEBAPP/sites/WEB