Tuesday, 19 June 2018

How to Install and Connect SharePoint Online PowerShell Module

SharePoint Online team focusing Microsoft Graph Api to provide common api experience for Office 365 users, but some Admin related activities still we need to use powershell module. Follow the below steps to install and connect SharePoint Management Shell.
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Note: If powershell console is already opened, close and open the powershell again after installing the above setup.
  • Now run the following command after replacing your tenant name to connect spo service.
Connect-SPOService -url https://<your tenant name>-admin.sharepoint.com
  • Once you have connected the SPO service, then you can run SPO management commands. The below command lists all spo sites.
Get-SPOSite | Select Title, Url
Read More...

Friday, 15 June 2018

How to increase Windows service startup timeout period

Problem:

Some software services may failed to start in slower machine and you will get following error events in Application event log.

Event ID: 7000

The ServiceName service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.

Event ID: 7009

A timeout was reached (30000 milliseconds) while waiting for the ServiceName service to connect.

Solution:

To fix this service startup problem, we need to increase default startup timeout period 30000 milliseconds (30 seconds). Follow the below steps to increase all windows services startup timeout.
  • Open Run window by clicking Start button -> click Run.
  • In Run window, type regedit, and then click OK to open Registry Editor.
  • Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
  • In the right pane, locate the ServicesPipeTimeout entry.
Note: If the ServicesPipeTimeout entry does not exist, first you should create it. Follow below steps:
  1. On the Edit menu, point to New, and then click DWORD Value.
  2. Type ServicesPipeTimeout, and then press ENTER.
  • One you locate (or created) ServicesPipeTimeout, right-click ServicesPipeTimeout, and then click Modify. Click Decimal, type 120000 (2 mins), and then click OK.
This value (120000) represents the time in milliseconds to wait for windows service to start before timeout.
  • Restart the computer once you done the changes.
How to increase Windows service startup timeout period
Read More...

Thursday, 14 June 2018

Find and Export all SharePoint Online Sites using Powershell

In this post, I am going to share powershell script to get a list of sites in Office 365. We can easily extract all sites using the SharePoint Online Management shell cmdlet Get-SPOSite.

Before proceed Install the SharePoint Online Management Shell:
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Note: If powershell console already opened, close and open the powershell again after installing the above setup.

We need admin site url to connect SharePoint Online service, you can refer this post to Get SharePoint Online Admin Site Url. Once you got the admin site url run the below script after replacing your AdminUrl to list all sites.
#Replace your admin site url
$AdminUrl = "https://contoso-admin.sharepoint.com/"
#Retrieve all site collections
Connect-SPOService -Url $AdminUrl
Get-SPOSite | Select Title, Url, Owner
If you want to retrieve all the available properties, run the below command, it will list all the attributes of first site.
Get-SPOSite | Select -First 1 | FL
You can also filter the sites based on any available property, the below command lists only sites with sharing capability enabled as ExternalUserSharingOnly.
Get-SPOSite | Where-Object {$_.SharingCapability -eq "ExternalUserSharingOnly"}
Run the below command to list sites with share capability disabled.
Get-SPOSite | Where-Object {$_.SharingCapability -eq "Disabled"}

Export all SharePoint Online Sites to CSV:

Run the below command to export all the required details of spo sites to csv file.
Get-SPOSite | Select Title, Url, Owner, SharingCapability, LastContentModifiedDate |
Export-CSV "C:\\SharePoint-Online-Sites.csv" -NoTypeInformation -Encoding UTF8
Read More...

Tuesday, 12 June 2018

Powershell : The term 'Connect-SPOService' is not recognized as the name of a cmdlet

Problem :

I have got the error message "The term 'Connect-SPOService' is not recognized as the name of a cmdlet" when I run the powershell cmdlet Connect-SPOService to connect SharePoint Online site.
Connect-SPOService : The term 'Connect-SPOService' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Connect-SPOService -url https://conotoso-admin.sharepoint.com
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-SPOService:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Solution :

The command Connect-SPOService belongs to SharePoint Online Management Shell, so before using this command we need to install the SPO Management Shell and import the module. You only need install once for each computer from which you are running SPO Powershell commands.

Install SharePoint Online Management Shell:

You can download and install the setup from this path : Download SharePoint Online Management Shell

Connect SharePoint Online Module:

Once you have installed the above setup, run the following command to import the SharePoint online powershell module.
Import-Module Microsoft.Online.SharePoint.Powershell
Then run the following commands to connect spo service and list all sites.
Connect-SPOService -url https://conotoso-admin.sharepoint.com 
Get-SPOSite | Select Title, Url
Read More...

Friday, 8 June 2018

Office 365 : How to get SharePoint Online Admin Site Url

You have to give your SharePoint admin site url as root scope when you work with SharePoint online PowerShell module and SharePoint Client Object Model (CSOM). The possible admin site url would be like below sample url.
https://tenantname-admin.sharepoint.com/
Consider your office 365 user id (userPrincipalName) is : "admin@contoso.onmicrosoft.com" and most probably your tenant name is "contoso" then your sharepoint admin site url should be below one.
https://contoso-admin.sharepoint.com/
You can test the url is correct or not by using this url as root scope with SharePoint Online Powershell module. The below connect your sharepoint admin site and list all sites.
$cred = Get-Credentials
Connect-SPOService -url "https://contoso-admin.sharepoint.com" -Credential $credential
Get-SPOSite | Select Title, Url
You can also get the correct url by connecting Office 365 Admin center site:
Steps to get sharepoint admin site url from Office 365 admin center
  • Now, you can view your admin site and get the correct admin site url as shown in below image.
how to get sharepoint admin site url

Read More...

Thursday, 7 June 2018

Powershel : Convert JSON String to PS Object and Vice-versa

Many software services moving towards cloud environment and providing APIs to communicate with service. To standardize this communication many software APIs use JSON format to receive and return data. In this post, I am going to share powershell script to convert json to object and convert object to json string.

Convert JSON content to PS Object :

You can easily convert json text into object using the powershell cmdlet ConvertFrom-Json. Consider the below sample JSON that might be a HTTP/HTTPS response content returned from some API.
$usersJson = '{"users":[
    { "username":"kevin", "email":"kevin@test.com" },
    { "username":"morgan", "email":"morgan@test.com" },
    { "username":"smith", "email":"smith@test.com" }
]}'
Run the following command to convert the above json string to ps object.
$usersObject = ConvertFrom-Json –InputObject $usersJson
Now you can easily list the ps object properties
PS C:\> $usersObject.users

username email
-------- -----
kevin    kevin@test.com
morgan   morgan@test.com
smith    smith@test.com

Convert PS Object to JSON String :

You can convert the above ps object into json text using the powershell cmdlet ConvertTo-Json.
$newUsersJson = $usersObject | ConvertTo-Json

parse json string as ps object and convert ps object to json string

Read More...

Wednesday, 6 June 2018

Powershell : The term 'Get-AzureADUser' is not recognized as the name of a cmdlet

Problem :

You might have received the error message "The term Get-AzureADUser is not recognized as the name of a cmdlet" when you run the Azure AD powershell cmdlet Get-AzureADUser to get Office 365 users.
The term 'Get-AzureADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:16
+ Get-AzureADUser <<<<
    + CategoryInfo          : ObjectNotFound: (Get-AzureADUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Solution :

The command Get-AzureADUser belongs to Azure Active Directory Powershell for Graph module, so before using this command we need to install and connect AzureAD powershell v2 module.

Install AzureAD module:

Open Powershell console with Run as administrator privilege and run the following command:
Install-Module AzureAD -Force

Connect/Load AzureAD module:

Once you have installed the Azure AD module, run the following command to load the module.
Connect-AzureAD
# Once you connected the AzureAD module, now run the Get-AzureADUser command.
Get-AzureADUser
Read More...

Powershell : The term 'Get-MsolUser' is not recognized as the name of a cmdlet

Problem :

You may receive the error "The term Get-MsolUser is not recognized as the name of a cmdlet" when you run the Azure AD powershell command Get-MsolUser to fetch Office 365 users.
The term 'Get-MsolUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:13
+ Get-MsolUser <<<<
    + CategoryInfo          : ObjectNotFound: (Get-MsolUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Solution :

The cmdlet Get-MsolUser belongs to Azure AD Powershell (V1) module (MSOnline), so before using this command we need to install and connect MSOnline module.

Install MSOnline module:

Earlier you need to download an executable (exe binary) file to install this module, but now Microsoft expired that file and you can install only through powershell. Open Powershell console with Run as administrator privilege and run the following command:
Install-Module MSOnline -Force

Connect/Import MSOnline module:

Once you have installed the MSOnline module, run the following command to connect MSOnline module.
Connect-MsolService
# Once you connect MsolService, now run the Get-MsolUser command.
Get-MsolUser
Read More...