Opening .msg eMails from SharePoint 2010

See Opening .msg e-mails in Outlook from a SharePoint 2010 document library for the full details.

cls
$snapIn = Get-PSSnapin | where-object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}
if($snapIn -eq $null) {    
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
$webApp = Get-SPWebApplication https://WEBAPP
If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains "application/vnd.ms-outlook")
{  
$webApp.AllowedInlineDownloadedMimeTypes.Add("application/vnd.ms-outlook")  
$webApp.Update()  
Write-Host "application/vnd.ms-outlook added to AllowedInlineDownloadedMimeTypes"
}

Find all groups in Site Collection using a specific permission level

Find all groups in Site Collection using a specific permission level. Helpful for removing outdated custom permission levels.

$siteUrl = "https://WEBAPP/sites/SITECOLLECTION"
$permission = "Restricted Read"
function Get-SPGroupByPermissionLevel([string]$url, [string]$permLevel) {
$spWeb = Get-SPWeb $url
$spGroupCollection = $spWeb.SiteGroups;
$group = $spGroupCollection | ? {$_.Roles | ? {$_.Name -eq $permLevel} }
$spWeb.Dispose()
return $group;
}
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl);
$spWebApp = $rootSite.WebApplication;
foreach($SPSite in $spWebApp.Sites)
{
$siteURL = $SPSite.URL;
Write-Host "SITEURL: $siteURL"
        $groups = Get-SPGroupByPermissionLevel $siteURL $permission;
        foreach($group in $groups)
        {
if($group -ne $NULL){
Write-Host "-Web "$siteURL "-Group "$group
}
}
$SPSite.Dispose();
}
$rootSite.Dispose();

“Add users to a SharePoint group” Disabled

In researching this error, the posted answers had to do with the site being created by code – and the solution was a change in the code.

However, it wasn’t my code creating the sites, but the migration tool I was using. Changing their code wasn’t an option. So if you have a site where the “Add users to a SharePoint group” drop-down is disabled, you can solve this in two ways.

Using the GUI:

Site Actions > Site Permissions – go into each group you want available in the drop down and make it the default group -leaving for last the actual group you want to make the default.

PowerShell Script:

Add all of the groups desired to be part of the dropdown – leaving the actual group you want to make the default last.

cls
$snapIn = Get-PSSnapin | where-object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}
if($snapIn -eq $null) {
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
$Web=Get-SPweb https://WEBAPP/sites/SITE/SUBSITE
$Web.AssociatedMemberGroup=$Web.SiteGroups["SITENAME Contributors"]
$Web.AssociatedMemberGroup=$Web.SiteGroups["SITENAME Manager"]
$Web.AssociatedMemberGroup=$Web.SiteGroups["SITENAME CUSTOM Group"]
$Web.AssociatedMemberGroup=$Web.SiteGroups["SITENAME Visitors"]
$Web.update()
$Web.dispose()

Export/Import Sub-Site with PowerShell

Thanks to Russ Ramirez’s SharePoint Blog for providing me with the answer I needed.  From his post, SPWeb move or clone in PowerShell, I was able to come up with the following script.

$moveFrom = https://WEBAPP1/sites/SITECOLLECTION/SITEA/SITEA1
$moveTo = https://WEBAPP2/sites/SITECOLLECTION/SITEB/SITEB1/SITEA1NEW
$backup = "E:\Backup\20120104_BACKUP.cmp"
$siteName = "SITE NAME"
$siteDesc = "SITE DESCRIPTION"
Get-SPWeb $moveFrom | Select-Object -Property WebTemplate, Configuration
# !! Based on the results of the Get-SPWeb, update the next line for Template (Concat WebTemplate + "#" + Configuration)
New-SPWeb -Url $moveTo -Template STS#0 -Name $siteName -Description $siteDesc
Export-SPWeb $moveFrom -Path $backup -IncludeVersions All -Verbose -CompressionSize 100000000
Import-SPWeb $moveTo -Path $backup -Force

Manage Timer Jobs with PowerShell

Following Pathik’s Blog I changed a few of my jobs to run 15 minutes past the hour:

Get-SPTimerJob | Format-Table -Property DisplayName,Id,LastRunTime,Status, Schedule
Get-SPTimerJob -identity 3f110578-5afa-4b8b-8dbf-496838a32005 | select Name, DisplayName, Schedule
Set-SPTimerJob “StateServiceExpiredSessionJobDefinition” -schedule "hourly between 15 and 15"

For more info see: Manage Timer Jobs with PowerShell

Print All PDF Files in Folders

I wonder if there’s a way to do this against a SharePoint Library: Print All PDF Files in Folders

Cleaning up illegal characters

I wish I had something like this years ago.  A way to do a bulk cleanup of illegal characters in file names before uploading and getting rejected by SharePoint:  Use PowerShell to check for illegal characters before uploading multiple files into SharePoint

PowerShell EnableVersioning_MajorVersionLimit_AllDocLibs

My TFS Admin colleague needed a script to go through all of the libraries in her project sites and turn on versioning with a 5 version limit.  We didn’t want to turn it on for all libraries, so that’s where the additional “notlike”s came in.

#Get site collection
  $site = Get-SPSite -Identity http://WEBAPP/sites/TFSSITECOLLECTION 
#Go through each site in the site collection
$site | Get-SPWeb -limit all | ForEach-Object { 
 write-host "Checking site:"$_.Title 
#Go through each document library in the site
 $_.GetListsOfType("DocumentLibrary") | where { $_.BaseTemplate -eq "DocumentLibrary" -and $_.Title - notlike "*Site*" -and $_.Title -notlike "*Templates*" -and $_.Title -notlike "*Style*"} | ForEach-Object {
 write-host "Library:"$_.Title 
#Make the list changes
  #$_.EnableVersioning = $true
  #$_.MajorVersionLimit = 5
#Update the list
  $_.Update()  
}  
}  
#Dispose of the site object
  $site.Dispose()

PowerShell List all Lists and their GUIDs

This PowerShell will list all of the lists in a subsite and their GUIDS. 

cls
$snapIn = Get-PSSnapin | where-object {$_.Name -eq "Microsoft.SharePoint.PowerShell"} 
if($snapIn -eq $null) {   
Add-PsSnapin Microsoft.SharePoint.PowerShell 
} 
$website = Get-SPWeb -identity https://WEBAPP/sites/SITE/WEB 
$website | ForEach-Object { 
write-host "Checking site:"$_.Title 
#Go through each List in the site   
$_.Lists | ForEach-Object { 
write-host "List:"$_.Title " - List Id:"$_.Id   
#Dispose of the site object   
$website.Dispose()   
}   
}
Follow

Get every new post delivered to your Inbox.