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