Yeah, I know - that’s a very odd title. Not sure how to explain it succinctly.
Anyway, I have an issue that I’m struggling with. I have an open ticket with Microsoft regarding some breaking changes that I’ve found with Windows Server 2012 R2. I’m not optimistic that they’ll be able to solve it, so I’m going to approach the idea from a different angle. It’s past my knowledge, though, so I could use some help.
In short, I’m having problems with a PowerShell script that uses the SharePoint Client Side Object Model (CSOM). To do CSOM, you need to get a context object and then explicitly load any collections or properties which aren’t populated by default. For example, to load up the list of subsites in a site, you would do something like this:
That will then populate $ctx.Web.Webs.
The function that I have takes $ctx and $ctx.Web.Webs as parameters. The breaking change (or so it seems) is that the function will evaluate $ctx.Web.Webs at call time and fail (because it hasn’t been loaded yet), whereas on non-2012-R2 it works perfectly fine. So I’m thinking of another way to do it.
I’m thinking one way to solve the issue would be to go ahead and pass in the $ctx object but then instead of having the object as the second parameter I instead have a string. So instead of calling
Load-CSOMObject –context $ctx –object $ctx.Web.WebsI’d call
Load-CSOMObject –context $ctx –objectString “Web.Webs”. Then, inside the function I’d need to build the equivalent of $ctx.Web.Webs using $ctx and “Web.Webs”. However, I have no idea whether or not this is possible. Does anyone know if it’s possible to dynamically build a an object that references a property or collection in another object using a string? Something like
$object = $ctx[$objectString]or
$object = $ctx.$objectString?
Thanks, everyone, for the help. I know this is a weird question.