Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 614657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:08:07+00:00 2026-05-13T18:08:07+00:00

I have a POSH script that sets a user’s access to a specific folder

  • 0

I have a POSH script that sets a user’s access to a specific folder for some files to read.

The user’s group gets assigned to the folder (which happens to be the same name).

I then created a new view, set it to default, and told it to display all files without folders.

This script has been working perfectly for 4 months but now some people want to use the mobile view and I am running into an issue. If a user does not have read access from the root directory to the folder in question, SharePoints mobile view will not show the folder.

For example the user has the following permissions set:
Limited Access on the root
Limited Access on the Alpha folder
Read access to the folder under Alpha

I need to make it so a user can view this in the mobile view.

Here is my code:

#region Start
# Create Connection to stopwatch diagnostics
[Void][System.Diagnostics.Stopwatch] $sw;
# New Stopwatch object
$sw = New-Object System.Diagnostics.StopWatch;
# Stop any watches that might be running
$sw.Stop();                                         
$sw.Start();
clear
[int]$a = 0;
# Which folders to assign
[array]$sections = "Alpha","Bravo","Charlie","Delta";
[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
#endregion

#region The meat and potatoes
foreach ($section in $sections) {
    #region get the Directories
    $pathtowd = "\\path\to\webdav\$section";                                    # UNC Path to the pivots
    $dirs = Get-ChildItem $pathtowd | Where-Object { $_.Attributes -band [System.IO.FileAttributes]::Directory }
    #endregion

    #region Connect to SharePoint
    $SPSite = New-Object Microsoft.SharePoint.SPSite("http://sharepoint");                  # Connect to SharePoint
    $OpenWeb = $SpSite.OpenWeb("/Downloads");                                               # Subsite of downloads
    #endregion
    [int]$i = 0;                                                                            # Integer to increment
    foreach ($dir in $dirs) {
        $verify_groups = $OpenWeb.groups | ? {$_.Name -eq "$dir"; }                         # Verify the groups
        if ($verify_groups -ne $null) {
            if ($dir.ToString() -eq $verify_groups.ToString()) {
                $i++;                                                                       # Increment the groups
                Write-Host "[", $sw.Elapsed.ToString(), "] -",$dir -F Green;                # Output status
                $path = "http://sharepoint/Downloads/Pivots/$section/" + $dir;              # Set the Path
                $spc = $OpenWeb.SiteGroups;                                                 # SharePoint connection
                $group = $spc[$dir];                                                        # Directory
                $roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($group); # Role Assignment connection
                $OpenWeb.GetFolder($path).Item.BreakRoleInheritance("true");                # Break inheritance
                $roleAssignment.RoleDefinitionBindings.Add($OpenWeb.RoleDefinitions["Read"]);# Set permissions
                $OpenWeb.GetFolder($path).Item.RoleAssignments.Add($roleAssignment);        # Add the role
                $OpenWeb.GetFolder($path).Item.Update();
            }
            else { Write-Host "[", $sw.Elapsed.ToString(), "] -", $verify_groups " is empty"; }
        }
    }
    Write-Host '[' $sw.Elapsed.ToString() '] - found '$i' Folders' -f Red;                  # Output Status
    $SPSite.Dispose();                                                                      # Dispose the connection
    $OpenWeb.Dispose();
    $a = $a+$i;                                                                             # Total Folders
}
#endregion

$sw.Stop();                                                                             # Stop the timer
[string]$howlong = $sw.Elapsed.ToString();                                              # How long
write-host "Updated in Time: " $howlong -F Green;                                       # Last message
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:08:07+00:00Added an answer on May 13, 2026 at 6:08 pm

    Found it. Took 4 hours straight of trial and error but it works. Hope this helps someone else out as well. Place before $OpenWeb.GetFolder($path).Item.Update();

    $returnGroups = $OpenWeb.GetFolder($path).Item.RoleAssignments | `
            where {`
             ($_.RoleDefinitionBindings -eq $OpenWeb.RoleDefinitions["Limited Access"]) -and `
             ($_.RoleDefinitionBindings -notcontains $OpenWeb.RoleDefinitions["Read"])`
            };
            if ($returnGroups -not $null)
            {
             foreach ($item in $returnGroups)
             {
              Write-Host "Removing: " $item.Member;
              $OpenWeb.GetFolder($path).Item.RoleAssignments.Remove($spc[$item.Member]);
             }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 390k
  • Answers 390k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes a tracking service will tell you when an activity… May 15, 2026 at 1:07 am
  • Editorial Team
    Editorial Team added an answer If that's an exact quote from your DNS GUI, then… May 15, 2026 at 1:07 am
  • Editorial Team
    Editorial Team added an answer I guess @foo = ("aAa", "bbb"); @bar = grep(/^aaa/i, @foo);… May 15, 2026 at 1:07 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.