I have to create custom action under standard menu(gear icon). Using below code I am able to create custom action on classic team site.
$siteAction = $context.Web.UserCustomActions.Add();
$siteAction.Group = "SiteActions";
$siteAction.Location = "Microsoft.SharePoint.StandardMenu";
$siteAction.Name = "Sample_CustomAction";
$siteAction.Sequence = 1000;
$siteAction.Url = $context.Url +"/_layouts/user.aspx"
$siteAction.Title = "Web Permissions";
$siteAction.Update();
$context.ExecuteQuery();
however, when tried the same code on modern team site, it says "Access denied. You do not have permission to perform this action or access this resource" I am able to access the site in browser. Please help.