Skip to content

Instantly share code, notes, and snippets.

View aflyen's full-sized avatar

Are Flyen aflyen

View GitHub Profile
@aflyen
aflyen / AutoFollowSitesInSharePoint2013.ps1
Last active February 8, 2018 12:32
Auto-Follow Sites in SharePoint 2013
# Get UserProfile Manager
$site = Get-SPSite -Limit 1
$serviceContext = Get-SPServiceContext($site)
$profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$profiles = $profileManager.GetEnumerator()
# Iterates through all the user profiles
foreach ($profile in $profiles)
{
$followingManager = New-Object Microsoft.Office.Server.Social.SPSocialFollowingManager($profile)
@aflyen
aflyen / EnableExportOnWebParts.ps1
Last active October 28, 2015 11:46
Enable export on web parts in SharePoint (on-premises)
# Configuration
$WebUrl = "http://intranet.contoso.com"
$PageUrl = "/Pages/default.aspx"
$WebPartName = "Documents"
# Enables export mode
$Web = Get-SPWeb $WebUrl
$File = $Web.GetFile($Web.ServerRelativeUrl + $PageUrl)
$File.CheckOut()
$Wpm = $File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
function Enable-CustomItemScheduling {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[Microsoft.SharePoint.Client.Web]$Web,
[Parameter(Mandatory=$true)]
[String]$PagesLibraryName
)
$List = $Web.Lists.GetByTitle($PagesLibraryName)
function Get-CustomLoadParameter {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[Microsoft.SharePoint.Client.ClientObject]$Object,
[Parameter(Mandatory=$true)]
[string]$PropertyName
)
# Reference: http://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell
$Context = Get-SPOContext
$Web = $Context.Site.RootWeb
$Context.Load($Web)
Execute-SPOQuery
Enable-CustomItemScheduling -Web $Web -PagesLibraryName "Pages"
# Configuration
$WebUrl = "http://teams.contoso.com/sites/team1"
$SiteAdminGroup = "CONTOSO\ContosoSiteAdmins"
# Set the AD group as site collection administrator
$Web = Get-SPWeb $WebUrl
$SiteAdminUser = $Web.EnsureUser($SiteAdminGroup)
$SiteAdminUser.IsSiteAdmin = $true
$SiteAdminUser.Update()
function Enable-CustomLikesRatingsOnLibrary {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[Microsoft.SharePoint.Client.Web]$Web,
[Parameter(Mandatory=$true)]
[String]$ListRelativeUrl
)
# Get required fields
# Connect to SharePoint Online site collection and get context
Connect-SPOnline -Url "https://TENANTID.sharepoint.com/sites/news
$Context = Get-SPOContext
$Web = $Context.Site.RootWeb
$Context.Load($Web)
Execute-SPOQuery
# Enable likes ratings
Enable-CustomLikesRatingsOnLibrary -Web $Web -ListRelativeUrl "Pages"
# Settings
$username = "aflyen@northcorp.no"
# Connect to Exchange Online
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
# Get current mailbox language settings
$Settings = Get-MailboxRegionalConfiguration -Identity $username
Write-Host "Before: $($Settings.Language)"
# Settings
$Username = "aflyen@northcorp.no"
# Connect to Azure AD
Connect-AzureAD
# Get user
$User = Get-AzureADUser -ObjectId $Username
Write-Host "Before: $($User.PreferredLanguage)"