Error running PS script on SharePoint Server As Setup Account


#powershell script - delete users personel sites - sharepoint 2010
#the scripts distributet "as-is." use on own risk. author give no warranties, guarantees or conditions.

#add sharepoint powershell snapin if not added
 if ((get-pssnapin "microsoft.sharepoint.powershell" -erroraction silentlycontinue) -eq $null) {
    add-pssnapin "microsoft.sharepoint.powershell"
}
[reflection.assembly]::loadwithpartialname("microsoft.office.server")

$mysitehosturl = "http://mysite/"
$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 

   if($profile.personalsite -ne $null)
   {
    $profile.personalsite.delete()
    write-host $accountname , " personel site deleted successfully"
   }
}
$mysite.dispose();

exception calling "delete" "0" argument(s): "access denied. (exception hresult: 0x80070005 (e_accessdenied))"
@ e:\temp\ps1\deletemysites.ps1:25 char:33
+        $profile.personalsite.delete <<<< ()
    + categoryinfo          : notspecified: (:) [], methodinvocationexception
    + fullyqualifiederrorid : dotnetmethodexception

this account has rights. opened powershell admin no idea wrong has thoughts?


chamy07

chamy,

another way verify if user using has permissions, use management shell sharepoint, log sql server, or open management studio , connect server.

under security --> logins, right click user account using (if not there doesn't have permissions), choose properties.

go user mappings , sharepoint_config database, user should have sharepoint_shell_access role enabled, if not run following command:

$configdbname = "sharepoint_config" $user = "domain\username"  $db = get-spdatabase | where-object { $_.name -eq $configdbname }  add-spshelladmin -username $user -database $db.id


if find post has answered question, please mark answer. if find post helpful in anyway, please click vote helpful.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS