Tue. Jan 4th, 2022
Function Create_Security_Group(){
    $exists=0
    $Error = $null

    try{
        $Group = Get-PnPGroup -Identity 'Custom Security Group' -ErrorAction SilentlyContinue

        if($Error -ne $null){
            Write-Host "Warning - Group not found" -ForegroundColor DarkYellow
            $Error.Clear()
            $exists=1
        }
    }Catch{
        $exists=1
        
    }

    if($exists  -eq 0 -or $exists  -eq 1){
        Write-Host "Creating Custom Security Group" -ForegroundColor Yellow
        try{ 
            New-PnPGroup -Title "Custom Security Group" -ErrorAction SilentlyContinue
            Set-PnPGroup -Identity "Custom Security Group"" -AddRole "Manager" -Owner "Site Owners" -ErrorAction SilentlyContinue
            if($Error -ne $null)
            {
                Write-Host "Error -" $_.Exception.Message -ForegroundColor Red
            }
            Write-host "Custom Security Group created" -ForegroundColor Green
        }catch{
            Write-Host "Error -" $_.Exception.Message -ForegroundColor Red
        }
    }
    else{
         write-host "Group already exists" -ForegroundColor Green
    }
}

This website uses cookies. By continuing to use this site, you accept our use of cookies.