Friday, October 30, 2015

Add SharePoint Security Group to All Lists or Libraries in a Site using PowerShell



This is sometimes very hectic for admins to add a new SharePoint Security group to a number of Lists and Libraries.

Using below code, it will be very easy to add a security group to all lists and libraries.

If you want to add security group to a specific type of library, you can add filter like the one below

if($spList.BaseTemplate -eq "10002")

For the information about base template follow the link


# Get Site
$spSite = Get-SPSite http://siteurl
# Get all web in current site
$spWebs = $spSite.AllWebs
# Set Permission level in variable
$PermissionLevel = "Read"
# Loop All Webs in site
foreach($web in $spWebs)
{
    # Get the Site Group from current Web which you want to add in Permissions for List/Library
       $spGroup = $web.SiteGroups["Visitors"]
    # Loop through all the lists/Libraries
       foreach($spList in $web.Lists)
       {
      
             
              # Break in Inheritance, this will allow you to add groups, otherwise it will not allow
              $spList.BreakRoleInheritance($true);
              # create Role Assignment  
              $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($spGroup)
              # Get the RoleDefinition for permission level
              $roleDefinition = $web.RoleDefinitions[$PermissionLevel];
              # Bind Role Definition
              $roleAssignment.RoleDefinitionBindings.Add($roleDefinition);
              # Add Role to List
              $spList.RoleAssignments.Add($roleAssignment)
              # Turn the Inheritance ON
              $spList.BreakRoleInheritance($false);
              # Update List
              $spList.Update();

             
       }
}

$spSite.Dispose()
$spWebs.Dispose()

Tuesday, October 27, 2015

The URL 'Filepath\Filename.xlxs' does not exists. It may refers to a nonexistent file or folder, or refer to a valid file or folder that is not in current web

All of sudden, while you are using SharePoint in routine a certain error start appearing while creating or uploading a file to a SharePoint list or library.

Error: The URL 'Filepath\Filename.xlxs' does not exists. It may refers to a nonexistent file or folder, or refer to a valid file or folder that is not in current web

While browsing through the application and you know that the library/list path is valid, just copy the correlation ID and see what happen in log.



Log will show some SQL Server error just like below.

SqlError: 'The transaction log for database 'WSS_Content_01' is full due to 'ACTIVE_TRANSACTION'. '    Source: '.Net SqlClient Data Provider' Number: 9002 State: 4 Class: 17 Procedure: 'proc_WriteStreamToSQL' LineNumber: 21 Server: 'Server909'

Unknown SQL Exception 9002 occurred. Additional error information from SQL Server is included below.  The transaction log for database 'WSS_Content_01' is full due to 'ACTIVE_TRANSACTION'.

Unknown SQL Exception 3903 occurred. Additional error information from SQL Server is included below.  The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

Solution:

There are two possibilities either the drive where your database file resides is full or the Log/Data file for database do not have enough space for further transaction. The SQL Exception 9002 occurs for the same reason.

If you know much about SQL Server, you can try giving more space to database files otherwise contact your DB Admin.

Monday, October 26, 2015

Office 365: all about managing users on SharePoint Online

Office 365: How to Remove user from SharePoint Online site

To remove a user from a security group or direct access to SharePoint online site, use Remove-SPOUser.

It has three parameters, two of them "Site" and "LoginName" are mandatory.

Site
      Site URL, where the user needs to be as site collection administrator.

LoginName
      Login Name of User.


Group
      Optional parameter specifying the group name where user exists.


Syntax


Remove-SPOUser -Site <SiteUrl> -LoginName <UserLogin> -Group <Security Group Name>
 
 

Office 365: How to set user as Site collection administrator

An existing Office 365 User can be set as Site collection administrator using cmdlet SET-SPOUser. 

Following are the parameters.

Site
      Site URL, where the user needs to be as site collection administrator.

LoginName
      Login Name of User.

IsSiteCollectionAdmin
      Boolean, try or false, true for setting as administrator, while false for removing a user as administrator.

Syntax


Set-SPOUser -Site <siteURL> -LoginName <UserLogin> -IsSiteCollectionAdmin <true/false>
 
 

Sunday, October 25, 2015

Office365: How to add user to SharePoint Online site using PowerShell

Use Add-SPOUser to add an existing Office 365 user to SharePoint online site.

Note: user performing the action must be SharePoint Online Global Administrator and the user which is being added exists in Office 365.

If you want to know how to add a new user in Office 365, please follow the link here.

Now coming back to the ADD-SPOUser, it has three parameters which all are mandatory.

Site
        Site URL where user needs to added.
LoginName
        Login Name of user
Group
       SharePoint Security Group name, where user will be added.

Syntax



Add-SPOUser -Site <SiteUrl> -LoginName <UserName> -Group <Group>
 
 
 
 Varify if user has been added using GET-SPOUser cmdlet.
 
 
 
 
 

Office 365: Add user to Admin Center

Follow the following steps to add user to Office 365 admin center.

  1. Sign in to Office 365 with your work or school account at URL https://portal.office.com
  2. Go to the Office 365 admin center by clicking the thumbnail as highlighted in the screen below.
  3. In the Left hand navigation pan, Choose Users and click Active Users. 
  4. Click "Add" or "Plus" icon as shown in the following screen shot.

  5. A Modal Popup for create user will appear
  6. Enter First Name and Last name, which are optional.
  7. Display name will be a combination of First and Last name or you can add one of your choice.
  8. User name will be part of email address, user will use to login to site. If tenant has more than one domain, select appropriate domain as well.
  9. Select one from the Auto generated or Type Password. If Auto generated, Office 365 will display a password on next screen. If Type Password, it will allow you to add a password.
  10. Type the Email address of the user where you want to receive information about this account.
  11. Last option is for License, which is assigned to this user. If you do not have any license, leave it for future assignment or select from the available option how many licenses you want to assign this user.
  12. Click "Create" and a new user will be created.

Saturday, October 24, 2015

Office 365: How to Get list of site User/Groups for a site using PowerShell

A list of all users can be generated using Get-SPOUser command in SharePoint Online Management Shell. Multiple parameters are available to be used with the cmdlet with detail as follows.

SITE

Site Parameter is mandatory and must be given for successful completion of the command. If only Site parameter is used, it will return all the user/groups for site mentioned against this parameter.

Example:

Get-SPOUser -Site https://shaoib.sharepoint.com
 
 
LOGINNAME
 
Login Name parameter retrieves the details of account mentioned in command.
 
Example:
 
Get-SPOUser -Site https://shaoib.sharepoint.com -Loginame "test@onmicrosoft.com" 


GROUP

If group parameter is used along with Site parameter, it will return all users in that group.

Exampe:

Get-SPOUser -Site https://shaoib.sharepoint.com -Group "Dev Users"
 
 
Export Users
 
Using below PowerShell Function, List of all users/groups can also be exported into a CSV file.



Function GetSiteUsers() {
$USers = Get-SPOUser -Site <SiteURL>
$Users | Export-Csv "C:\SiteUsers.csv" -notype
}
 
 
Exported File:
 
 
 


Friday, October 23, 2015

Create Content Types in Office 365




Every now and then we have to create content types in SharePoint either on premises or cloud. Content Types are reusable collection of settings like columns for list and libraries in SharePoint. These bind together items with their information.

We can create custom content types other than the default content types available in Office 365.
Follow the following steps to create a new content type in O365


  1.  Go to site
  2. Click on the settings icon on the top right corner
  3. Go to Web Designer Galleries section and click “Site content types”
  4. Click “create” on the top of Content Types list.
  5. On the new Content Type page fill all the information and click save.