Powershell get all items that use a template
up vote
2
down vote
favorite
The title pretty much says it all - I've looked at the docs but I just keep finding Get-Item
and Get-ItemTempate
.
Lets say I have a template with id 123456, I want to get all items that are using this template. How would I do that?
powershell-extensions
New contributor
add a comment |
up vote
2
down vote
favorite
The title pretty much says it all - I've looked at the docs but I just keep finding Get-Item
and Get-ItemTempate
.
Lets say I have a template with id 123456, I want to get all items that are using this template. How would I do that?
powershell-extensions
New contributor
How would you do that in C#?
– Alan Płócieniak
2 days ago
Something likeallItems.Where(p => p.TemplateIdList.Contains("123456"));
Let me see if I can powershell that! - Disclaimer - New to Sitecore so I don't know what exists and what doesn't...
– Rick
2 days ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
The title pretty much says it all - I've looked at the docs but I just keep finding Get-Item
and Get-ItemTempate
.
Lets say I have a template with id 123456, I want to get all items that are using this template. How would I do that?
powershell-extensions
New contributor
The title pretty much says it all - I've looked at the docs but I just keep finding Get-Item
and Get-ItemTempate
.
Lets say I have a template with id 123456, I want to get all items that are using this template. How would I do that?
powershell-extensions
powershell-extensions
New contributor
New contributor
New contributor
asked 2 days ago
Rick
1405
1405
New contributor
New contributor
How would you do that in C#?
– Alan Płócieniak
2 days ago
Something likeallItems.Where(p => p.TemplateIdList.Contains("123456"));
Let me see if I can powershell that! - Disclaimer - New to Sitecore so I don't know what exists and what doesn't...
– Rick
2 days ago
add a comment |
How would you do that in C#?
– Alan Płócieniak
2 days ago
Something likeallItems.Where(p => p.TemplateIdList.Contains("123456"));
Let me see if I can powershell that! - Disclaimer - New to Sitecore so I don't know what exists and what doesn't...
– Rick
2 days ago
How would you do that in C#?
– Alan Płócieniak
2 days ago
How would you do that in C#?
– Alan Płócieniak
2 days ago
Something like
allItems.Where(p => p.TemplateIdList.Contains("123456"));
Let me see if I can powershell that! - Disclaimer - New to Sitecore so I don't know what exists and what doesn't...– Rick
2 days ago
Something like
allItems.Where(p => p.TemplateIdList.Contains("123456"));
Let me see if I can powershell that! - Disclaimer - New to Sitecore so I don't know what exists and what doesn't...– Rick
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
This should do it for you.
$defaultPath = "/sitecore/content"
[Sitecore.Data.ID]$articleId = "{03360FC1-B4C0-4770-9E1D-79E8317B74DD}"
$articles = Find-Item -Index sitecore_master_index `
-Where 'TemplateId = @0 and Path.StartsWith(@1)' `
-WhereValues $articleId, $defaultPath | Initialize-Item
Another way using template name and Criteria.
$articles = Find-Item `
-Index sitecore_master_index `
-Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Article"},
@{Filter = "Equals"; Field = "_language"; Value = "en"},
@{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/content" }
If I do aWrite-Host $_.FullPath
on everything in$articles
, then I get quite a log of duplicates. Any idea why this would happen?
– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
1
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
add a comment |
up vote
3
down vote
I would recommend you use the Get-ItemReferrer
command. This is based on the Link Database and should be extremely fast.
A similar question was asked here.
$sampleItemTemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$sampleItemTemplateItem = Get-Item -Path "master:" -ID $sampleItemTemplateId
Get-ItemReferrer -Item $sampleItemTemplateItem
As you can see below, all referrers are returned. You can then filter out with Where-Object
if you want to exclude content, media, templates, etc.
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
This should do it for you.
$defaultPath = "/sitecore/content"
[Sitecore.Data.ID]$articleId = "{03360FC1-B4C0-4770-9E1D-79E8317B74DD}"
$articles = Find-Item -Index sitecore_master_index `
-Where 'TemplateId = @0 and Path.StartsWith(@1)' `
-WhereValues $articleId, $defaultPath | Initialize-Item
Another way using template name and Criteria.
$articles = Find-Item `
-Index sitecore_master_index `
-Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Article"},
@{Filter = "Equals"; Field = "_language"; Value = "en"},
@{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/content" }
If I do aWrite-Host $_.FullPath
on everything in$articles
, then I get quite a log of duplicates. Any idea why this would happen?
– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
1
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
add a comment |
up vote
2
down vote
accepted
This should do it for you.
$defaultPath = "/sitecore/content"
[Sitecore.Data.ID]$articleId = "{03360FC1-B4C0-4770-9E1D-79E8317B74DD}"
$articles = Find-Item -Index sitecore_master_index `
-Where 'TemplateId = @0 and Path.StartsWith(@1)' `
-WhereValues $articleId, $defaultPath | Initialize-Item
Another way using template name and Criteria.
$articles = Find-Item `
-Index sitecore_master_index `
-Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Article"},
@{Filter = "Equals"; Field = "_language"; Value = "en"},
@{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/content" }
If I do aWrite-Host $_.FullPath
on everything in$articles
, then I get quite a log of duplicates. Any idea why this would happen?
– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
1
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
This should do it for you.
$defaultPath = "/sitecore/content"
[Sitecore.Data.ID]$articleId = "{03360FC1-B4C0-4770-9E1D-79E8317B74DD}"
$articles = Find-Item -Index sitecore_master_index `
-Where 'TemplateId = @0 and Path.StartsWith(@1)' `
-WhereValues $articleId, $defaultPath | Initialize-Item
Another way using template name and Criteria.
$articles = Find-Item `
-Index sitecore_master_index `
-Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Article"},
@{Filter = "Equals"; Field = "_language"; Value = "en"},
@{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/content" }
This should do it for you.
$defaultPath = "/sitecore/content"
[Sitecore.Data.ID]$articleId = "{03360FC1-B4C0-4770-9E1D-79E8317B74DD}"
$articles = Find-Item -Index sitecore_master_index `
-Where 'TemplateId = @0 and Path.StartsWith(@1)' `
-WhereValues $articleId, $defaultPath | Initialize-Item
Another way using template name and Criteria.
$articles = Find-Item `
-Index sitecore_master_index `
-Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Article"},
@{Filter = "Equals"; Field = "_language"; Value = "en"},
@{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/content" }
answered 2 days ago
Chris Auer
6,82511041
6,82511041
If I do aWrite-Host $_.FullPath
on everything in$articles
, then I get quite a log of duplicates. Any idea why this would happen?
– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
1
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
add a comment |
If I do aWrite-Host $_.FullPath
on everything in$articles
, then I get quite a log of duplicates. Any idea why this would happen?
– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
1
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
If I do a
Write-Host $_.FullPath
on everything in $articles
, then I get quite a log of duplicates. Any idea why this would happen?– Rick
2 days ago
If I do a
Write-Host $_.FullPath
on everything in $articles
, then I get quite a log of duplicates. Any idea why this would happen?– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
(using the first example btw)
– Rick
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
multiple languages? This is is reading directly from the index, so we have to know why there are multiple items in your index.
– Chris Auer
2 days ago
1
1
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
Ah potentially - I'll investigate if that is the case. Thanks
– Rick
2 days ago
add a comment |
up vote
3
down vote
I would recommend you use the Get-ItemReferrer
command. This is based on the Link Database and should be extremely fast.
A similar question was asked here.
$sampleItemTemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$sampleItemTemplateItem = Get-Item -Path "master:" -ID $sampleItemTemplateId
Get-ItemReferrer -Item $sampleItemTemplateItem
As you can see below, all referrers are returned. You can then filter out with Where-Object
if you want to exclude content, media, templates, etc.
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
add a comment |
up vote
3
down vote
I would recommend you use the Get-ItemReferrer
command. This is based on the Link Database and should be extremely fast.
A similar question was asked here.
$sampleItemTemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$sampleItemTemplateItem = Get-Item -Path "master:" -ID $sampleItemTemplateId
Get-ItemReferrer -Item $sampleItemTemplateItem
As you can see below, all referrers are returned. You can then filter out with Where-Object
if you want to exclude content, media, templates, etc.
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
add a comment |
up vote
3
down vote
up vote
3
down vote
I would recommend you use the Get-ItemReferrer
command. This is based on the Link Database and should be extremely fast.
A similar question was asked here.
$sampleItemTemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$sampleItemTemplateItem = Get-Item -Path "master:" -ID $sampleItemTemplateId
Get-ItemReferrer -Item $sampleItemTemplateItem
As you can see below, all referrers are returned. You can then filter out with Where-Object
if you want to exclude content, media, templates, etc.
I would recommend you use the Get-ItemReferrer
command. This is based on the Link Database and should be extremely fast.
A similar question was asked here.
$sampleItemTemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$sampleItemTemplateItem = Get-Item -Path "master:" -ID $sampleItemTemplateId
Get-ItemReferrer -Item $sampleItemTemplateItem
As you can see below, all referrers are returned. You can then filter out with Where-Object
if you want to exclude content, media, templates, etc.
answered 2 days ago
Michael West
7,83121450
7,83121450
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
add a comment |
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
Nice one Mike. Didn't know that existed.
– Chris Auer
2 days ago
add a comment |
Rick is a new contributor. Be nice, and check out our Code of Conduct.
Rick is a new contributor. Be nice, and check out our Code of Conduct.
Rick is a new contributor. Be nice, and check out our Code of Conduct.
Rick is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f15165%2fpowershell-get-all-items-that-use-a-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How would you do that in C#?
– Alan Płócieniak
2 days ago
Something like
allItems.Where(p => p.TemplateIdList.Contains("123456"));
Let me see if I can powershell that! - Disclaimer - New to Sitecore so I don't know what exists and what doesn't...– Rick
2 days ago