How do you change the sort order of items using PowerShell
I have some items created using New-Item
but they are automatically sorted alphabetically. I would much prefer these items to be sorted by Created date.
How do you change the sort order of items using SPE?
powershell-extensions
add a comment |
I have some items created using New-Item
but they are automatically sorted alphabetically. I would much prefer these items to be sorted by Created date.
How do you change the sort order of items using SPE?
powershell-extensions
add a comment |
I have some items created using New-Item
but they are automatically sorted alphabetically. I would much prefer these items to be sorted by Created date.
How do you change the sort order of items using SPE?
powershell-extensions
I have some items created using New-Item
but they are automatically sorted alphabetically. I would much prefer these items to be sorted by Created date.
How do you change the sort order of items using SPE?
powershell-extensions
powershell-extensions
asked Dec 10 at 16:24
Michael West
8,18621450
8,18621450
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
There are two places I can think of when it comes to changing the sort order.
Item level sort order
Select an item and change the view in the ribbon to include Standard fields. You should see something like this:
These values can be changed from the ribbon or programmatically and the value is an integer (e.g. 100, 200).
Example: The following changes an item's sort order. Assumes you know the precise order you want to achieve.
$item = Get-Item -Path "master:" -ID "{C9CB2B73-04B3-43F8-B36A-D64C77E35F79}"
$item.Editing.BeginEdit()
$item.Fields["__Sortorder"].Value = 200
$item.Editing.EndEdit() > $null
Subitem level sort order
This is likely the option you want to go with. You don't have to worry about changing the sort manually every time, and it goes beyond a simple numerical value.
Example: The following sets the sort order on the parent node which results in this behavior cascading to the immediate children.
function Set-SortOrder {
[CmdletBinding(DefaultParameterSetName="SortOrder")]
param(
[Parameter()]
[ValidateNotNull()]
[item]$Item,
[Parameter(ParameterSetName="SortOrder")]
[ValidateSet("Created","Default","Display name","Logical","Reverse","Updated")]
[string]$SortOrder,
[Parameter(ParameterSetName="Reset")]
[switch]$Reset
)
$subitemsSortOrderFieldId = "{6FD695E7-7F6D-4CA5-8B49-A829E5950AE9}"
$sortValue = & {
switch($SortOrder) {
"Created" {
"{C1FF011E-B02A-44E3-8444-9FC89CFC28CE}"
}
"Default" {
"{781247D2-9785-400F-8935-C818EC757967}"
}
"Display name" {
"{44D1A0D2-E17B-4DAA-ADDF-53F2E8F58525}"
}
"Logical" {
"{EA1DECB2-B4F2-4AE0-99A8-30FDED9B8B50}"
}
"Reverse" {
"{C3E3F0E3-0162-4F1F-AB3E-40348E371A3F}"
}
"Updated" {
"{32416A95-4197-4D33-8CE7-7BB4FFEBEB42}"
}
}
}
$item.Editing.BeginEdit()
if($Reset.IsPresent) {
$item.Fields[$subitemsSortOrderFieldId].Reset()
} else {
$item.Fields[$subitemsSortOrderFieldId].Value = $sortValue
}
$item.Editing.EndEdit() > $null
}
$item = Get-item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
# Reset the subitem sorting to Standard values
Set-SortOrder -Item $item -Reset
# Change the subitem sorting to based on Created Date
Set-SortOrder -Item $item -SortOrder Created
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "664"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f15471%2fhow-do-you-change-the-sort-order-of-items-using-powershell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are two places I can think of when it comes to changing the sort order.
Item level sort order
Select an item and change the view in the ribbon to include Standard fields. You should see something like this:
These values can be changed from the ribbon or programmatically and the value is an integer (e.g. 100, 200).
Example: The following changes an item's sort order. Assumes you know the precise order you want to achieve.
$item = Get-Item -Path "master:" -ID "{C9CB2B73-04B3-43F8-B36A-D64C77E35F79}"
$item.Editing.BeginEdit()
$item.Fields["__Sortorder"].Value = 200
$item.Editing.EndEdit() > $null
Subitem level sort order
This is likely the option you want to go with. You don't have to worry about changing the sort manually every time, and it goes beyond a simple numerical value.
Example: The following sets the sort order on the parent node which results in this behavior cascading to the immediate children.
function Set-SortOrder {
[CmdletBinding(DefaultParameterSetName="SortOrder")]
param(
[Parameter()]
[ValidateNotNull()]
[item]$Item,
[Parameter(ParameterSetName="SortOrder")]
[ValidateSet("Created","Default","Display name","Logical","Reverse","Updated")]
[string]$SortOrder,
[Parameter(ParameterSetName="Reset")]
[switch]$Reset
)
$subitemsSortOrderFieldId = "{6FD695E7-7F6D-4CA5-8B49-A829E5950AE9}"
$sortValue = & {
switch($SortOrder) {
"Created" {
"{C1FF011E-B02A-44E3-8444-9FC89CFC28CE}"
}
"Default" {
"{781247D2-9785-400F-8935-C818EC757967}"
}
"Display name" {
"{44D1A0D2-E17B-4DAA-ADDF-53F2E8F58525}"
}
"Logical" {
"{EA1DECB2-B4F2-4AE0-99A8-30FDED9B8B50}"
}
"Reverse" {
"{C3E3F0E3-0162-4F1F-AB3E-40348E371A3F}"
}
"Updated" {
"{32416A95-4197-4D33-8CE7-7BB4FFEBEB42}"
}
}
}
$item.Editing.BeginEdit()
if($Reset.IsPresent) {
$item.Fields[$subitemsSortOrderFieldId].Reset()
} else {
$item.Fields[$subitemsSortOrderFieldId].Value = $sortValue
}
$item.Editing.EndEdit() > $null
}
$item = Get-item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
# Reset the subitem sorting to Standard values
Set-SortOrder -Item $item -Reset
# Change the subitem sorting to based on Created Date
Set-SortOrder -Item $item -SortOrder Created
add a comment |
There are two places I can think of when it comes to changing the sort order.
Item level sort order
Select an item and change the view in the ribbon to include Standard fields. You should see something like this:
These values can be changed from the ribbon or programmatically and the value is an integer (e.g. 100, 200).
Example: The following changes an item's sort order. Assumes you know the precise order you want to achieve.
$item = Get-Item -Path "master:" -ID "{C9CB2B73-04B3-43F8-B36A-D64C77E35F79}"
$item.Editing.BeginEdit()
$item.Fields["__Sortorder"].Value = 200
$item.Editing.EndEdit() > $null
Subitem level sort order
This is likely the option you want to go with. You don't have to worry about changing the sort manually every time, and it goes beyond a simple numerical value.
Example: The following sets the sort order on the parent node which results in this behavior cascading to the immediate children.
function Set-SortOrder {
[CmdletBinding(DefaultParameterSetName="SortOrder")]
param(
[Parameter()]
[ValidateNotNull()]
[item]$Item,
[Parameter(ParameterSetName="SortOrder")]
[ValidateSet("Created","Default","Display name","Logical","Reverse","Updated")]
[string]$SortOrder,
[Parameter(ParameterSetName="Reset")]
[switch]$Reset
)
$subitemsSortOrderFieldId = "{6FD695E7-7F6D-4CA5-8B49-A829E5950AE9}"
$sortValue = & {
switch($SortOrder) {
"Created" {
"{C1FF011E-B02A-44E3-8444-9FC89CFC28CE}"
}
"Default" {
"{781247D2-9785-400F-8935-C818EC757967}"
}
"Display name" {
"{44D1A0D2-E17B-4DAA-ADDF-53F2E8F58525}"
}
"Logical" {
"{EA1DECB2-B4F2-4AE0-99A8-30FDED9B8B50}"
}
"Reverse" {
"{C3E3F0E3-0162-4F1F-AB3E-40348E371A3F}"
}
"Updated" {
"{32416A95-4197-4D33-8CE7-7BB4FFEBEB42}"
}
}
}
$item.Editing.BeginEdit()
if($Reset.IsPresent) {
$item.Fields[$subitemsSortOrderFieldId].Reset()
} else {
$item.Fields[$subitemsSortOrderFieldId].Value = $sortValue
}
$item.Editing.EndEdit() > $null
}
$item = Get-item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
# Reset the subitem sorting to Standard values
Set-SortOrder -Item $item -Reset
# Change the subitem sorting to based on Created Date
Set-SortOrder -Item $item -SortOrder Created
add a comment |
There are two places I can think of when it comes to changing the sort order.
Item level sort order
Select an item and change the view in the ribbon to include Standard fields. You should see something like this:
These values can be changed from the ribbon or programmatically and the value is an integer (e.g. 100, 200).
Example: The following changes an item's sort order. Assumes you know the precise order you want to achieve.
$item = Get-Item -Path "master:" -ID "{C9CB2B73-04B3-43F8-B36A-D64C77E35F79}"
$item.Editing.BeginEdit()
$item.Fields["__Sortorder"].Value = 200
$item.Editing.EndEdit() > $null
Subitem level sort order
This is likely the option you want to go with. You don't have to worry about changing the sort manually every time, and it goes beyond a simple numerical value.
Example: The following sets the sort order on the parent node which results in this behavior cascading to the immediate children.
function Set-SortOrder {
[CmdletBinding(DefaultParameterSetName="SortOrder")]
param(
[Parameter()]
[ValidateNotNull()]
[item]$Item,
[Parameter(ParameterSetName="SortOrder")]
[ValidateSet("Created","Default","Display name","Logical","Reverse","Updated")]
[string]$SortOrder,
[Parameter(ParameterSetName="Reset")]
[switch]$Reset
)
$subitemsSortOrderFieldId = "{6FD695E7-7F6D-4CA5-8B49-A829E5950AE9}"
$sortValue = & {
switch($SortOrder) {
"Created" {
"{C1FF011E-B02A-44E3-8444-9FC89CFC28CE}"
}
"Default" {
"{781247D2-9785-400F-8935-C818EC757967}"
}
"Display name" {
"{44D1A0D2-E17B-4DAA-ADDF-53F2E8F58525}"
}
"Logical" {
"{EA1DECB2-B4F2-4AE0-99A8-30FDED9B8B50}"
}
"Reverse" {
"{C3E3F0E3-0162-4F1F-AB3E-40348E371A3F}"
}
"Updated" {
"{32416A95-4197-4D33-8CE7-7BB4FFEBEB42}"
}
}
}
$item.Editing.BeginEdit()
if($Reset.IsPresent) {
$item.Fields[$subitemsSortOrderFieldId].Reset()
} else {
$item.Fields[$subitemsSortOrderFieldId].Value = $sortValue
}
$item.Editing.EndEdit() > $null
}
$item = Get-item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
# Reset the subitem sorting to Standard values
Set-SortOrder -Item $item -Reset
# Change the subitem sorting to based on Created Date
Set-SortOrder -Item $item -SortOrder Created
There are two places I can think of when it comes to changing the sort order.
Item level sort order
Select an item and change the view in the ribbon to include Standard fields. You should see something like this:
These values can be changed from the ribbon or programmatically and the value is an integer (e.g. 100, 200).
Example: The following changes an item's sort order. Assumes you know the precise order you want to achieve.
$item = Get-Item -Path "master:" -ID "{C9CB2B73-04B3-43F8-B36A-D64C77E35F79}"
$item.Editing.BeginEdit()
$item.Fields["__Sortorder"].Value = 200
$item.Editing.EndEdit() > $null
Subitem level sort order
This is likely the option you want to go with. You don't have to worry about changing the sort manually every time, and it goes beyond a simple numerical value.
Example: The following sets the sort order on the parent node which results in this behavior cascading to the immediate children.
function Set-SortOrder {
[CmdletBinding(DefaultParameterSetName="SortOrder")]
param(
[Parameter()]
[ValidateNotNull()]
[item]$Item,
[Parameter(ParameterSetName="SortOrder")]
[ValidateSet("Created","Default","Display name","Logical","Reverse","Updated")]
[string]$SortOrder,
[Parameter(ParameterSetName="Reset")]
[switch]$Reset
)
$subitemsSortOrderFieldId = "{6FD695E7-7F6D-4CA5-8B49-A829E5950AE9}"
$sortValue = & {
switch($SortOrder) {
"Created" {
"{C1FF011E-B02A-44E3-8444-9FC89CFC28CE}"
}
"Default" {
"{781247D2-9785-400F-8935-C818EC757967}"
}
"Display name" {
"{44D1A0D2-E17B-4DAA-ADDF-53F2E8F58525}"
}
"Logical" {
"{EA1DECB2-B4F2-4AE0-99A8-30FDED9B8B50}"
}
"Reverse" {
"{C3E3F0E3-0162-4F1F-AB3E-40348E371A3F}"
}
"Updated" {
"{32416A95-4197-4D33-8CE7-7BB4FFEBEB42}"
}
}
}
$item.Editing.BeginEdit()
if($Reset.IsPresent) {
$item.Fields[$subitemsSortOrderFieldId].Reset()
} else {
$item.Fields[$subitemsSortOrderFieldId].Value = $sortValue
}
$item.Editing.EndEdit() > $null
}
$item = Get-item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
# Reset the subitem sorting to Standard values
Set-SortOrder -Item $item -Reset
# Change the subitem sorting to based on Created Date
Set-SortOrder -Item $item -SortOrder Created
answered Dec 10 at 16:24
Michael West
8,18621450
8,18621450
add a comment |
add a comment |
Thanks for contributing an answer to Sitecore Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f15471%2fhow-do-you-change-the-sort-order-of-items-using-powershell%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