Skip to content

Commit 771cc85

Browse files
authored
Add Get-PnPUserOneDriveLocation cmdlet (#5382)
* Add user OneDrive location cmdlet * Address OneDrive location review feedback
1 parent e230151 commit 771cc85

5 files changed

Lines changed: 138 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
99
## [Current nightly]
1010

1111
### Added
12+
- Added `Get-PnPUserOneDriveLocation` cmdlet to retrieve SharePoint Online multi-geo location details for a user's OneDrive personal site. [#5382](https://github.com/pnp/powershell/pull/5382)
1213
- Added `Remove-PnPGeoAdministrator` cmdlet to remove SharePoint Online geo administrators. [#5380](https://github.com/pnp/powershell/pull/5380)
1314
- Added `Get-PnPGeoAdministrator` cmdlet to retrieve SharePoint Online geo administrators. [#5378](https://github.com/pnp/powershell/pull/5378)
1415
- Added `Add-PnPGeoAdministrator` cmdlet to add SharePoint Online multi-geo administrators. [#5381](https://github.com/pnp/powershell/pull/5381)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Get-PnPUserOneDriveLocation
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPUserOneDriveLocation.html
8+
---
9+
10+
# Get-PnPUserOneDriveLocation
11+
12+
## SYNOPSIS
13+
Returns the SharePoint Online multi-geo location details for a user's OneDrive personal site.
14+
15+
## SYNTAX
16+
17+
```powershell
18+
Get-PnPUserOneDriveLocation -UserPrincipalName <String> [-Connection <PnPConnection>]
19+
```
20+
21+
## DESCRIPTION
22+
Returns the SharePoint Online multi-geo location, OneDrive personal site URL, site ID, and user principal name for the specified user.
23+
24+
## EXAMPLES
25+
26+
### EXAMPLE 1
27+
28+
```powershell
29+
Get-PnPUserOneDriveLocation -UserPrincipalName user@contoso.com
30+
```
31+
32+
Returns the OneDrive personal site location details for the specified user.
33+
34+
## PARAMETERS
35+
36+
### -Connection
37+
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by specifying `-ReturnConnection` on `Connect-PnPOnline` or by executing `Get-PnPConnection`.
38+
39+
```yaml
40+
Type: PnPConnection
41+
Parameter Sets: (All)
42+
43+
Required: False
44+
Position: Named
45+
Default value: None
46+
Accept pipeline input: False
47+
Accept wildcard characters: False
48+
```
49+
50+
### -UserPrincipalName
51+
The user principal name of the user whose OneDrive personal site location details should be returned.
52+
53+
```yaml
54+
Type: String
55+
Parameter Sets: (All)
56+
57+
Required: True
58+
Position: Named
59+
Default value: None
60+
Accept pipeline input: False
61+
Accept wildcard characters: False
62+
```
63+
64+
## OUTPUTS
65+
66+
### PnP.PowerShell.Commands.Model.UserPersonalSiteLocation
67+
Returns an object with `UserPrincipalName`, `Location`, `MySiteUrl`, and `SiteId` properties.
68+
69+
## RELATED LINKS
70+
71+
[Get-PnPUserAndContentMoveState](Get-PnPUserAndContentMoveState.md)
72+
73+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using PnP.PowerShell.Commands.Attributes;
2+
using PnP.PowerShell.Commands.Base;
3+
using PnP.PowerShell.Commands.Model;
4+
using PnP.PowerShell.Commands.Utilities.MultiGeo;
5+
using System.Management.Automation;
6+
7+
namespace PnP.PowerShell.Commands.Admin
8+
{
9+
[Cmdlet(VerbsCommon.Get, "PnPUserOneDriveLocation")]
10+
[RequiredApiApplicationPermissions("sharepoint/Sites.FullControl.All")]
11+
[RequiredApiDelegatedPermissions("sharepoint/AllSites.FullControl")]
12+
[OutputType(typeof(UserPersonalSiteLocation))]
13+
public class GetUserOneDriveLocation : PnPSharePointOnlineAdminCmdlet
14+
{
15+
[Parameter(Mandatory = true)]
16+
[ValidateNotNullOrEmpty]
17+
public string UserPrincipalName { get; set; }
18+
19+
protected override void ExecuteCmdlet()
20+
{
21+
var multiGeoRestApiClient = new MultiGeoRestApiClient(AdminContext);
22+
WriteObject(multiGeoRestApiClient.GetUserPersonalSiteLocation(UserPrincipalName));
23+
}
24+
}
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
namespace PnP.PowerShell.Commands.Model
4+
{
5+
/// <summary>
6+
/// Contains the SharePoint Online multi-geo location details for a user's OneDrive personal site.
7+
/// </summary>
8+
public class UserPersonalSiteLocation
9+
{
10+
/// <summary>
11+
/// The user principal name for the OneDrive owner.
12+
/// </summary>
13+
public string UserPrincipalName { get; set; }
14+
15+
/// <summary>
16+
/// The SharePoint Online multi-geo location code for the user's OneDrive personal site.
17+
/// </summary>
18+
public string Location { get; set; }
19+
20+
/// <summary>
21+
/// The URL of the user's OneDrive personal site.
22+
/// </summary>
23+
public string MySiteUrl { get; set; }
24+
25+
/// <summary>
26+
/// The site collection identifier of the user's OneDrive personal site.
27+
/// </summary>
28+
public Guid SiteId { get; set; }
29+
}
30+
}

src/Commands/Utilities/MultiGeo/MultiGeoRestApiClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ internal class MultiGeoRestApiClient
5151
private const string MultiGeoApiVersionsPath = "MultiGeoApiVersions";
5252
private const string DeleteVerbString = "DELETE";
5353
private const string PatchVerbString = "PATCH";
54+
private const string UserPersonalSiteLocationMinimumApiVersion = "1.0";
55+
private const string UserPersonalSiteLocationPath = "UserPersonalSiteLocation('{0}')";
5456
private const string UserMoveJobsMinimumApiVersion = "1.0";
5557
private const string UserMoveJobsByMoveIdMinimumApiVersion = "1.2.2";
5658
private const string UserMoveJobsReportMinimumApiVersion = "1.3.2";
@@ -262,6 +264,13 @@ internal UserAndContentMoveState GetUserAndContentMoveState(string userPrincipal
262264
return Get<UserAndContentMoveState>(path, apiVersion);
263265
}
264266

267+
internal UserPersonalSiteLocation GetUserPersonalSiteLocation(string userPrincipalName)
268+
{
269+
var apiVersion = GetCurrentApiVersion(UserPersonalSiteLocationMinimumApiVersion);
270+
var path = string.Format(CultureInfo.InvariantCulture, UserPersonalSiteLocationPath, ProcessSpecialChars(userPrincipalName));
271+
return Get<UserPersonalSiteLocation>(path, apiVersion);
272+
}
273+
265274
internal UserAndContentMoveState GetUserAndContentMoveState(Guid odbMoveId)
266275
{
267276
var apiVersion = GetCurrentApiVersion(UserMoveJobsByMoveIdMinimumApiVersion);

0 commit comments

Comments
 (0)