SitecorePowerShell / Console

Sitecore PowerShell Extensions
https://doc.sitecorepowershell.com/
Other
114 stars 70 forks source link

Get-Item -ID without -Path #431

Closed pveller closed 9 years ago

pveller commented 9 years ago

Hey Guys,

Love SPE! All kinds of item manipulations in bulk and import / transformations are sooooo much easier to build. Very "fluid".

I was scripting something today and I needed a Get-Item by ID. I figured I could do something like:

Get-Item -Path " " -ID "{GUID}"

It works but it's a little ugly. The Get-Item wouldn't run without a -Path and wouldn't accept an empty string as a value. I think a version that just accepts the ID or Uri without Path is warranted. Let me know what you think!

AdamNaj commented 9 years ago

Hi Pavel,

Thanks for the kind words. I'm reading your blog quite religiously and admire your input to the community so It means a lot to me that you're using it!

So the problems is that the cmdlet is really not our cmdlet but rather PowerShell's itself and it works with whatever provider/drive the runspace has currently specified as its location, e.g. The -ID has no meaning in context of regular file system, that is why you need to provide a context. in general I just use a dot to say that I want it to use the "current provider", like:

Get-Item . -ID "{GUID}"

In a smilar vein you can avoid it looking bad simply by stating your purpose explicitly and providing a database like:

Get-Item master:\ -ID "{GUID}"
pveller commented 9 years ago

Oh, now it makes perfect sense. Thank you Adam!

p.s. I hope to see you on the SUGCON NA. We ought to do some behind the scenes geekout on ZenGarden vs. (or is it "plus" ?) SCORE :)

AdamNaj commented 9 years ago

Definitely! Looking forward to it!