Thursday, March 17, 2016

Permission audit report for site and all sub sites using PowerShell

Use below script to get Permission audit report for site and all sub sites using PowerShell,

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$URL="https://intranet.contoso.com/sales/mysite/"

     $site = Get-SPSite $URL

     #Write the Header to "Tab Separated Text File"

        "Site Name`t  URL `t Group Name `t User Account `t User Name `t E-Mail" | out-file "E:\Ulhas\UsersandGroupsRpt.txt"
   

     #Iterate through all Webs

      foreach ($web in $site.AllWebs)

      {

        #Write the Header to "Tab Separated Text File"

        "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "E:\Ulhas\UsersandGroupsRpt.txt" -append

         #Get all Groups and Iterate through  

         foreach ($group in $Web.groups)

         {

                "`t  `t $($Group.Name) `t   `t `t " | out-file "E:\Ulhas\UsersandGroupsRpt.txt" -append

                #Iterate through Each User in the group

                       foreach ($user in $group.users)

                        {

                           #Exclude Built-in User Accounts

                    if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))

                    {

                                "`t  `t  `t  $($user.LoginName)  `t  $($user.name) `t  $($user.Email)" | out-file "E:\Ulhas\UsersandGroupsRpt.txt" -append

                             }

                        }

         }

       }
    $site.dispose();

    write-host "Report Generated at E:\Ulhas\UsersandGroupsRpt.txt"

Populate people picker field with logged in user in SharePoint using JS

Please use below code to populate people picker in SharePoint online, <script src="https://ajax.googleapis.com/ajax/libs/jquery/3....