Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Exception calling "Remove" / Bad variable type when removing SiteGroup with PowerShell

$
0
0

Hello,

I am trying to remove all site groups in a site collection through Powershel by using the $Web.SiteGroups.Remove() function.

When doing so i get the following exception:

Exception calling "Remove" with "1" argument(s): "Unable to cast COM object of type
'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'. This operation
failed because the QueryInterface call on the COM component for the interface with IID '{BDEADF28-C265-11D0-BCED-00A0C90AB50F}' failed
due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE))."
+                 $sitegroups.Remove($sitegroup)
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidCastException
 

My code is the following:

$webapp = Get-SPWebApplication http://workdev.contoso.local

$allsites = Get-SPSite -WebApplication $webapp
foreach ($site in $allsites)
{

            $rootweb = $site.RootWeb;
        $sitegroups = $rootweb.SiteGroups;
            foreach ($sitegroup in $sitegroups)
            {
                $sitegroups.Remove($sitegroup);
            }

}

I have tried it as well with RemoveByID with the same outcome. The SiteGroups are properly read and listed only the Remove just doesn't work. I have tried also to call the command with ToString() but no luck.

Any help is appreciated!

Thank you in advance,

Ioannis




Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>