Home > Software design >  Cannot Get Get-MgSite to return CreatedBy or CreatedByUser
Cannot Get Get-MgSite to return CreatedBy or CreatedByUser

Time:11-02

I'm using the Microsoft Graph PowerShell SDK to try and get some data from SharePoint sites using the Get-MgSite command. I'm running this command specifically

$site = Get-MgSite -SiteId <siteId> -Property Id,DisplayName,Name,WebUrl,CreatedDateTime,CreatedBy,CreatedByUser

I also tried this command

$site = Get-MgSite -SiteId <siteId> -Property Id,DisplayName,Name,WebUrl,CreatedDateTime,CreatedBy -ExpandProperty CreatedByUser

The $site variable contains all the requested items from the Property parameter except for the CreatedBy and CreatedByUser. I see in the enter image description here

CodePudding user response:

As per the documentation , there is no Createdby.CreatedByUser property avaialable ,you can check "createdDateTime" property which is inherited from baseItem , please see the list of property available - https://learn.microsoft.com/en-us/graph/api/resources/site?view=graph-rest-1.0#properties

Hope this helps

Thanks

CodePudding user response:

createdByUser is a relationship defined for baseItem, so you need to use expand.

Get-MgSite -SiteId $siteId -Property "id,displayName,name,webUrl,createdDateTime,createdBy" -ExpandProperty "createdByUser" 

But the response from GET /v1.0/sites/{site-id} endpoint is quite unexpected

GET /v1.0/sites/{site-id}

returns properties: createdDateTime,description,id,lastModifiedDateTime,name, webUrl,displayName,root,siteCollection.

According to the documentation createdBy,lastModifiedBy,lastModifiedDateTime defined on baseItem are missing in the response.

GET /v1.0/sites/{site-id}?$select=id,displayName,name,webUrl,createdDateTime,createdBy&$expand=createdByUser

returns only createdDateTime,name,webUrl,displayName.

id,createdBy,createdByUser are missing.

It seems to me that there is a bug on the server side.

  • Related