Monday, 24 December 2018

How to enable 'save site as template' in SharePoint Online

Enable save site as template is blocked by default in SharePoint Online. This may because of multiple reasons-
  1.  Scripting is disabled by default so Enabling scripting will enable that option also.
  2. If Scripting is enabled then 'Publishing Feature' should be checked. If publishing feature is enabled then 'Save site as template' will be not available
We can enable Scripting by web admin as well as by PowerShell. Enabling by web admin will take upto 24 hour to enable but by powershell we can do that immediately.

#Config Parameters

$AdminSiteURL="https://xxxxxx-admin.onmicrosoft.com"   
$SiteURL="https://xxxxxx.onmicrosoft.com"

#Get Credentials to connect 

$Cred = Get-Credential


#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
#Disable DenyAddAndCustomizePages Flag
Set-SPOSite $SiteURL -DenyAddAndCustomizePages $False

Monday, 17 December 2018

Broken Image link Handling

Missing images will either just display nothing, or display a [ ? ] style box when their source cannot be found. Instead, you may want to replace that with a "missing image" graphic that you are sure exists so there is better visual feedback that something is wrong. Or, you might want to hide it entirely. This is possible because images that a browser can't find fire off an "error" JavaScript event we can watch for.
// Replace source
$('img').on("error", function() {
  $(this).attr('src', '/images/missing.png');
});

// Or, hide them
$("img").on("error", function() {
  $(this).hide();
});
Additionally, you may wish to trigger some kind of Ajax action to send an email to a site admin when this occurs.

How to find all external users using PowerShell?

Users outside of the organizations can be invited to collaborate to SharePoint Online as "External Users". As Microsoft says:
"An external user is someone outside of your organization who can access your SharePoint Online sites and documents but does not have a license for your SharePoint Online or Microsoft Office 365 subscription. External users are not employees, contractors, or onsite agents for you or your affiliates.

SharePoint Online: How to Get External Users?
As part of governance policies, we wanted to take control over external sharing, So I had to see how many external users are added to SharePoint Online and where. The Get-SPOExternalUser cmdlet displays a list of all external users in our Office 365 tenant. For an external user to be listed using this PowerShell cmdlet, they need to have accepted the invitation to the SharePoint Online environment, and have logged in at least once.

Find External Users in SharePoint Online: 
To view external users in SharePoint Online, there was a page in Old Office 365 admin center: External Sharing >> External User. But this page was deprecated. So, we are left with PowerShell! Open SharePoint Online Management Shell and run the below script to view external users SharePoint Online:

1
2
3
4
5
6
7
8
#Connect to SharePoint Online Tenant Admin
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$Cred = Get-Credential
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
#Get External Users
Get-SPOExternalUser | Select DisplayName,Email,AcceptedAs,WhenCreated | Format-Table
But wait! The Get-SPOExternalUser cmdlet has a limitation of returning first 50 users only! So, we need to amend the script a bit to get all external users in SharePoint Online.
1
2
3
4
5
6
7
Try {
    For ($x=0;;$x+=50) {
        $ExternalUsers += Get-SPOExternalUser -PageSize 50 -Position $x -ErrorAction Stop
    }
}
Catch {}
$ExternalUsers
This retrieves all external users of the SharePoint Online tenant.

Get external users of a specific site collection:
Specify the "SiteUrl" parameter to retrieve external users of the specific site collection. E.g. 

1
Get-SPOExternalUser -Position 0 -PageSize 50 -SiteUrl <Your-Site-Url>
This gets the external users on a specific SharePoint site collection.

SharePoint Online Find External Users and Export to CSV:
You have to loop through each collection to get the list of external users. The following PowerShell script allows you to iterate through each site collection and figure out the external users. Lets combine everything and export list of external users to a CSV file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput ="C:\Temp\ExternalUsersRpt.csv"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
#Get All Site Collections
$SiteCollections  = Get-SPOSite -Limit All
#Iterate through each site collection and get external users
Foreach ($Site in $SiteCollections)
{
    Write-host -f Yellow "Checking Site Collection:"$Site.URL
    Try {
        For ($x=0;;$x+=50) {
            $ExternalUsers += Get-SPOExternalUser -SiteUrl $Site.Url -Position $x -PageSize 50 -ErrorAction Stop | Select DisplayName,EMail,InvitedBy,AcceptedAs,WhenCreated,@{Name = "SiteUrl" ; Expression = {$Site.url}
        }
    }
}
catch {}
}
#Export the Data to CSV file
$ExternalUsers | Export-Csv -Path $ReportOutput -NoTypeInformation
This generates SharePoint Online External user report!

Alternate Method to Get All External Users - Site Collection Wise:
Lately, I found some issues in Get-SPOExternalUser cmdlet. In some cases, It doesn't return all external users. So, Lets use Get-SPOUser cmdlet to get external users by site collection.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput ="C:\Temp\ExternalUsersRpt.csv"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
#Get all Site Collections
$SitesCollection = Get-SPOSite -Limit ALL
$ExternalUsers=@()
#Iterate through each site collection
ForEach($Site in $SitesCollection)
{
    Write-host -f Yellow "Checking Site Collection:"$Site.URL
    #Get All External users of the site collection
    $ExtUsers = Get-SPOUser -Limit All –Site $Site.URL | Where {$_.LoginName -like "*#ext#*" -or $_.LoginName -like "*urn:spo:guest*"}
    If($ExtUsers.count -gt 0)
    {
        Write-host -f Green "Found $($ExtUsers.count) External User(s)!"
        $ExternalUsers += $ExtUsers
    }
}
#Export the Data to CSV file
$ExternalUsers | Export-Csv -Path $ReportOutput -NoTypeInformation

Featured post

What is SharePoint?

Microsoft SharePoint is an extensible platform that provides a range of products that can help organizations with solution for a variety...