$web=Get-SPWeb "https://portal/PWA/Subweb"
$group=$web.SiteGroups["Groupname"]
$roleAssignment=New-Object Microsoft.SharePoint.SPRoleAssignment($group)
$roleDefinition=$web.RoleDefinitions["Read"]
$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
$web.RoleAssignments.Add($roleAssignment);
Here it fails with an error:
Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an object."
Why? Groupname and Securitylevel checked
$web.Update()
$web.Dispose()