Hi,
I have tried to use a couple of the different scripts I have found on the web to automatically find all the user profiles that have been synchronized from AD and provision the My Sites prior to the usre logging in. However, I keep getting the same error when trying to run any of them. This is on Windows Server 2013 with SharePoint 2013 Enterprise. My Site Host is setup and if a user manually goes to start their My Site it will provision for them. The user I am running poershell as does have full control of the User Profile Application Service. Code is attached and here is my error. Any advice?
#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
#[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
{System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# some variables we can change
$mysiteHostUrl = "http://servername:9090/"
$personalSiteGlobalAdmin = "domain\SP_Admin"
$personalSiteGlobalAdminNot ="sp_admin@domain.local"
$personalSiteGlobalAdminDisplayName = "SharePoint Admin"
$mysite = Get-SPSite $mysiteHostUrl
$context = [Microsoft.Office.Server.ServerContext]::GetContext($mysite)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$AllProfiles = $upm.GetEnumerator()
foreach($profile in $AllProfiles)
{
$DisplayName = $profile.DisplayName
$AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
write-host $DisplayName
write-host $AccountName
# Adds restrictions to eliminate any service accounts or admin accounts
if($AccountName -notlike "*svc*" -and $AccountName -notlike "*admin*" )
{
if($profile.PersonalSite -eq $Null)
{
write-host "Creating personel site for" $AccountName
$profile.CreatePersonalSite()
# Adding an extra admin for personel sites
# $pweb = $profile.PersonalSite.OpenWeb()
# $pweb.AllUsers.Add($personalSiteGlobalAdmin,$personalSiteGlobalAdminNot,$personalSiteGlobalAdminDisplayName,$null);
# $padm= $pweb.AllUsers[$personalSiteGlobalAdmin];
# $padm.IsSiteAdmin = $true;
# $padm.Update();
# $pweb.Dispose();
write-host "Personal Site Admin has assigned"
}
else
{
write-host $AccountName ," has already personel site"
}
}
}
$mysite.Dispose();New-Object : Exception calling ".ctor" with "1" argument(s): "UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have 9be0bfb7-d6f3-48f6-8fc5-9e374491faa4"
At C:\Users\TSDemoAdmin01\Desktop\NewScripts\CreateAllMySitesForAllUsers.ps1:46 char:9
+ $upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($cont ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At C:\Users\TSDemoAdmin01\Desktop\NewScripts\CreateAllMySitesForAllUsers.ps1:49 char:1
+ $AllProfiles = $upm.GetEnumerator()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
My Ramblings @ http://alanwhitehouse.wordpress.com and My Tweets @ http://www.twitter.com/alanwhitehouse