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

Error creating a SharePoint group using PowerShell - Cannot find an overload for "Add" and the argument count: "4".

$
0
0

Hi All,
I am trying to create a SharePoint Online group using PowerShell but keep get an error message. The code and error message are show below:

*************** Code Example 1 ***************
$loc = "C:\Users\User1\Desktop\dll\"
$user ="AlanHardy@Outlook.com"
$site = "https://CompanySite.sharepoint.com/sites/Dev1/"
Set-Location $loc
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Write-Host "Add Password"
$SecPass = Read-Host -AsSecureString
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site);
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$SecPass)
$context.Credentials = $cred
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
$web.SiteGroups.Add("Test Group", "GaryRed@outlook", "MarkApple@outlook", "Description")
$ownerGroup.Update()
$context.ExecuteQuery()

*************** ERROR MESSAGE ***************
Cannot find an overload for "Add" and the argument count: "4".
At line:21 char:1
+ $web.SiteGroups.Add("Test Group", "GaryRed@outlook", "MarkApple@outlook", " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

You cannot call a method on a null-valued expression.
At line:22 char:1
+ $ownerGroup.Update()
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
*************************************

I also tried:

*************** Code Example 2 ***************
$loc = "C:\Users\User1\Desktop\dll\"
$user ="AlanHardy@Outlook.com"
$site = "https://CompanySite.sharepoint.com/sites/Dev1/"
Set-Location $loc
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Write-Host "Add Password"
$SecPass = Read-Host -AsSecureString
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site);
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$SecPass)
$context.Credentials = $cred
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
$groupMemberUser = $web.EnsureUser("TinaBrown@Outlook.com")
$groupOwnerUser = $web.EnsureUser("NickYoung@Outlook.com")
$context.Load($groupMemberUser)
$context.Load($groupOwnerUser)
$context.ExecuteQuery()
$web.SiteGroups.Add("Test Group", $groupMemberUser, $groupOwnerUser, "Group Description")
$context.ExecuteQuery()

*************** ERROR MESSAGE ***************
Cannot find an overload for "Add" and the argument count: "4".
At line:27 char:1
+ $web.SiteGroups.Add("Test Group", $groupMemberUser, $groupOwnerUser,  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
**************************************

I have even tried :
$web.SiteGroups.Add("XX", $web.SiteUsers["AnyUser@outlook.com"], $web.SiteUsers["AnyUser@outlook.com"], "test")

but still get the same error message

I hope you can help
Colin











Viewing all articles
Browse latest Browse all 7589

Trending Articles



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