Working with Items

Command Introduction

The majority of scripts written with SPE contain one or more of the following commands:
Get-Item
Get-ChildItem
New-Item
Remove-Item
Move-Item
Copy-Item
  • Use this to retrieve a single item. Throws an error if the item does not exist.
  • Use when Sitecore query: or fast: is required. May return more than 1 item.
1
Get-Item -Path "master:\content\home"
Copied!
  • Use to return an item's children and grandchildren.
1
Get-ChildItem -Path "master:\content\home" -Recurse
Copied!
  • Use to create an item based on a specified data template.
1
New-Item -Path "master:\content\home" -Name "Demo" -ItemType "Sample/Sample Item"
2
# or
3
New-Item -Path "master:\content\home" -Name "Demo" -ItemType "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
Copied!
  • Use to delete or recycle an item.
  • Accepts items returned by Get-Item and Get-ChildItem.
1
Get-Item -Path "master:\content\home\delete-me" | Remove-Item
Copied!
  • Use to transfer an item from one location to another.
1
Move-Item -Path "master:\content\home\Demo" -Destination "master:\content\home\Demo1"
Copied!
  • Use to duplicate an item from one location to another.
1
# Add -PassThru to output the new item
2
Copy-Item -Path "master:\content\home\Demo1" -Destination "master:\content\home\Demo2"
Copied!

Command Parameters

The following commands provide you with the core methods needed to manage your content. Due to the nature of Windows PowerShell, commands such as these are extended with custom parameters and switches using Dynamic Parameters. These parameters are then added to the command at the time of use and only appear when the conditions are right. We've provided this table to help you discover the hidden gems within each command.
Parameter Name
Description
Copy-Item
Get-Item
Get-ChildItem
Move-Item
New-Item
Remove-Item
AmbiguousPaths
More than one item matches the criteria so show them all.
-
Database
The specified database will be used. Requires the ID to be set.
DestinationItem
Parent item to receive the copied item.
FailSilently
Unauthorized access errors will be suppressed
ForceId
Forces the new item to use a specified GUID
ID
Matches the item by ID.
Item
Instance item.
Language
Specifies the languages to include.
Parent
Specifies the parent item.
Permanently
Specifies the item should be deleted rather than recycled.
Query
Matches the items by an XPath query.
StartWorkflow
Initiates the default workflow, if any.
TransferOptions
Options flag used when copying from one database to another.
Uri
Matches the item by ItemUri.
Version
Specifies the version to include.
Legend: "–" - not applicable; "✓" - available.
Below we will show how to use each command with the Windows PowerShell syntax followed by some examples of the common C# equivalent.

Finding Items

If you have retrieved your items directly using the Sitecore API you can still add the nice wrapper. You can do that by piping them through the Initialize-Item command. We'll show an example of this later.
Check out some performance details when using different methods of querying items on the Sitecore StackExchange.

Get-Item : by Path

Example: The following will retrieve the item based on the Sitecore path.
1
PS master:\> Get-Item -Path master:\content\home
2
3
Name Children Languages Id TemplateName
4
---- -------- --------- -- ------------
5
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Copied!
As you may have noticed, the /sitecore portion of the path is unnecessary. This is because the Sitecore item is represented by the root item of the drive master: and is therefore optional.
Let's have a look at the equivalent code in C#.
1
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
2
Sitecore.Data.Items.Item item = master.GetItem("/sitecore/content/home");
Copied!
The above will return the latest version of the item in your current language. But what if you want the item in another language? No problem!
Example: The following will retrieve the Danish version of the Home item.
1
PS master:\> Get-Item -Path master:/content/home -Language da | Format-Table -Property DisplayName, Language, Id, Version, TemplateName
2
3
DisplayName Language ID Version TemplateName
4
----------- -------- -- ------- ------------
5
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Copied!
I've formatted the output above to show you that indeed the right language was returned. The command supports wildcards for both -Language and -Version parameters. You may have also noticed that the forward and backward slashes can be used interchangeably.
Example: The following retrieves the latest version for all languages of an item.
1
PS master:\> Get-Item -Path master:/content/home -Language * | Format-Table -Property DisplayName, Language, Id, Version, TemplateName
2
3
DisplayName Language ID Version TemplateName
4
----------- -------- -- ------- ------------
5
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
6
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
7
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
8
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
9
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
10
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Copied!
Notice that the item with language en-US at its third version.
Example: The following retrieves the item in all languages and versions.
1
PS master:\> Get-Item -Path master:/content/home -Language * -Version *| Format-Table -Property DisplayName, Language, Id, Version, TemplateName
2
3
DisplayName Language ID Version TemplateName
4
----------- -------- -- ------- ------------
5
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
6
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
7
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
8
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
9
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2 Sample Item
10
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
11
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
12
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Copied!
You can see that specifying the language and version using the wildcard will retrieve all possible variants of an item. The wildcard can also include a partial match like en-*. The use of that filter would return all items in the English language, ignoring the region.

Get-ChildItem : by Path

Example: The following retrieves the child items in all languages and versions.
1
PS master:\> Get-ChildItem -Path master:/content -Language * -Version * | Format-Table -Property DisplayName, Language, Id, Version, TemplateName
2
3
DisplayName Language ID Version TemplateName
4
----------- -------- -- ------- ------------
5
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
6
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
7
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
8
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
9
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2 Sample Item
10
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
11
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
12
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Copied!

Get-Item : Sitecore query

It's not always most efficient to operate on items by traversing the tree using Get-ChildItem. This is especially true if you need to work on large trees but need to select only a few items (e.g. a specific template). For this we’ve introduced support for the Sitecore query within our provider.
Important to note that the query format sometimes requires the use of a # before and after paths when they contain reserved keywords or spaces.
Example: The following retrieves all items beneath the path /sitecore/content/ with the template of Sample Item.
1
PS master:\> Get-Item -Path master: -Query "/sitecore/content//*[@@templatename='Sample Item']"
2
3
Name Children Languages Id TemplateName
4
---- -------- --------- -- ------------
5
Copy of Home True {en, de-DE, es-ES, pt... {503713E5-F9EE-4847-AEAF-DD13FD853004} Sample Item
6
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Copied!
Example: The following retrieves all items beneath the path /sitecore/content/ with the template of Sample Item in all versions and languages.
1
PS master:\> Get-Item -Path master: -Query "/sitecore/content//*[@@templatename='Sample Item']" -Language * -Version * | Format-Table -Property DisplayName, Language, Id, Version, TemplateName -AutoSize
2
3
DisplayName Language ID Version TemplateName
4
----------- -------- -- ------- ------------
5
Home de-DE {503713E5-F9EE-4847-AEAF-DD13FD853004} 1 Sample Item
6
Hjem da {503713E5-F9EE-4847-AEAF-DD13FD853004} 1 Sample Item
7
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
8
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
9
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
10
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
11
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2 Sample Item
12
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
13
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
14
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Copied!
Example: The following retrieves items matching the query with a specified ISO date and present in a report dialog.
1
$isoDate = [Sitecore.DateUtil]::ToIsoDate([datetime]::Today)
2
Get-Item -Path master: -Query "/sitecore/content/home//*[@__Publish > '$($isoDate)']" |
3
Show-ListView -Property ID,Name,ItemPath
Copied!

Get-Item : Sitecore Fast query

Example: The following returns items with a specific template under a given root using Fast query.
1
$rootItemId = "{839085D0-C279-47C6-83C9-9CC28E7C111E}"
2
$rootItem = Get-Item -Path "master:" -ID $rootItemId
3
$templateId = "{759BA7B1-A216-467E-A37C-2B8D7F1A713C}"
4
5
$query = "fast:$($rootItem.ItemPath)//*[@@templateid='$($templateId)']"
6
Get-Item -Path "master:" -Query $query
Copied!

Get-Item : by XPath

The setup is not exactly like you would find in the XPath Builder but should get the job done. Read more about it here.
Example: The following retrieves items matching an XPath query.
1
$query = "ancestor-or-self::*[@@templatename='Sample Item']"
2
3
# Retrieve the items with Axes and a given context item.
4
$SitecoreContextItem.Axes.SelectItems($query)
5
6
# Retrieve the items using the Query class and context item.
7
# Retrieve the items by prepending the context path to the query.
8
Get-Item -Path "master:" -Query ("$($SitecoreContextItem.Paths.Path)/$query")
Copied!

Get-Item : by Id

Example: The following retrieves an item by id.
1
PS master:\> Get-Item -Path master: -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
2
3
Name Children Languages Id TemplateName
4
---- -------- --------- -- ------------
5
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Copied!

Get-Item : by Uri

The Uri encodes the language and version within the path.
Example: The following retrieves an item by uri.
1
PS master:\> Get-Item -Path master: -Uri "sitecore://master/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}?lang=en&ver=1"
2
3
Name Children Languages Id TemplateName
4
---- -------- --------- -- ------------
5
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Copied!
In all the examples you'll notice we specified the database. Windows PowerShell needs to know which provider to execute within. This also signals to SPE to show the dynamic parameters. Other examples of providers include the following:
  • HKLM: - The registry provider for HKEY_LOCAL_MACHINE.
  • C: - The filesystem provider for the C drive.

Get-Item : select properties

The following examples make use of custom PropertySet for the command Select-Object.
Example: The following uses the PSSecurity PropertySet.
1
PS master:\ >Get-Item -Path "master:\content\home" | Select-Object -Property PSSecurity
2
3
Name ID __Owner __Security
4
---- -- ------- ----------
5
Home {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} sitecore\admin au|sitecore\michael|pe|+item:read|
Copied!
Example: The following uses the PSTemplate PropertySet.
1
PS master:\> Get-Item -Path "/sitecore/media library/Images/SPE/kitten1" | Select-Object -Property PSTemplate
2
3
Name ID BaseTemplate
4
---- -- ------------
5
kitten1 {E58FA823-3CAF-43A1-A5ED-FBE24D3C21B4} {Image, File, Standard template, Media classification...}
Copied!
Example: The following uses the PSImage PropertySet.
1
PS master:\> Get-Item -Path "/sitecore/media library/Images/SPE/kitten1" | Select-Object -Property PSImage
2
3
Name : kitten1
4
ID : {E58FA823-3CAF-43A1-A5ED-FBE24D3C21B4}
5
Alt : Yay
6
Width : 225
7
Height : 225
8
Extension : jpg
9
Size : 6593
Copied!
Example: The following uses the PSSchedule PropertySet.
1
PS master:\> Get-Item -Path "/sitecore/system/Tasks/Schedules/Content Testing/Calculate Statistical Relevancy" | Select-Object -Property PSSchedule
2
3
Name : Calculate Statistical Relevancy
4
ID : {C7533E65-A1D6-4F99-9F12-0AB157299D80}
5
Schedule : 1900101|19000101|127|1.00:00
6
Last run : 1/1/0001 12:00:00 AM
7
Command : {6A79C206-0CD2-4DDD-9DFF-5BF21E002931}
8
Items :
Copied!

Get-Item : properties with field type

Example: The following accesses the Image field casted to the type Sitecore.Data.Fields.ImageField.
1
$item = Get-Item -Path "master:\content\home"
2
$item._.Image.Alt
Copied!
Note: You can use ._ and .PSFields to gain access to the typed field.
Example: The following accesses the Link field casted to the type Sitecore.Data.Fields.LinkField. From there you can see all of the available properties.
1
PS master:\> $currentItem = Get-Item -Path 'master:\content\home\sample-item'
2
PS master:\> $currentItem.PSFields."LinkFieldName"
3
4
Anchor :
5
Class :
6
InternalPath : /sitecore/content/home/sample-item/
7
IsInternal : True
8
IsMediaLink : False
9
LinkType : internal
10
MediaPath :
11
QueryString :
12
Target :
13
TargetID : {263293D3-B1B3-4C2C-9A75-6BD418F376BC}
14
TargetItem : Sitecore.Data.Items.Item
15
Text : CLICK HERE
16
Title :
17
Url :
18
Root : link
19
Xml : #document
20
InnerField : <link linktype="internal" text="CLICK HERE" querystring="" target="" id="{263293D3-B1B3-4C2C-9A75-6BD418F376BC}" />
21
Value : <link linktype="internal" text="CLICK HERE" querystring="" target="" id="{263293D3-B1B3-4C2C-9A75-6BD418F376BC}" />
Copied!
Example: The following finds all of the TextFields and outputs to the console.
1
$item = Get-Item -Path "master:\content\home"
2
foreach($field in $item.Fields) {
3
$item.PSFields."$($field.Name)" |
4
Where-Object { $_ -is [Sitecore.Data.Fields.TextField] }
5
}
Copied!

Editing Items

Get-Item : then change item properties

We often see the following two ways of accessing and changing fields used in scripts. One uses Set-ItemProperty and the other is more natural to a Sitecore developer.
Example: The following sets the title property using Set-ItemProperty.
1
PS master:\> Set-ItemProperty -Path master:/content/home -Name "Title" -Value "New Title"
Copied!
Example: The following sets the title and clears the branch id using .Editing.BeginEdit and .Editing.EndEdit methods.
1
$item = Get-Item master:/content/home
2
$item.Editing.BeginEdit()
3
$item["Title"] = "New Title"
4
$item.BranchId = [Guid]::Empty # or a new value if changing it
5
$item.Editing.EndEdit()
Copied!
Note: The above example may also be written in the ISE where no console prompt is visible.
The previous examples work but are not the most efficient ways to change item content. The items returned by the provider expose the Sitecore item fields as automatic PowerShell properties.
If the property name on the data template contains a space, such as `Closing Date`, then you will need to wrap the field name in quotes (single or double).
Example: The following sets the title property using the automated PowerShell property.
1
$item = Get-Item -Path master:/content/home
2
$item.Title = "New Title"
3
$item."Closing Date" = [datetime]::Today
Copied!
Example: The following changes the display name of the item.
1
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
2
$item."__Display name" = "I Like Turtles"
Copied!
This technique may be used for a wide variety of property types. There are a other hidden gems in those properties. For example if we detect that the field is a Date or Datetime field, we will return System.DateTime typed value from a field rather than the System.String Sitecore stores internally.
Example: The following gets the created date.
1
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
2
$item.__Created
3
4
# Monday, April 07, 2008 1:59:00 PM
Copied!
Example: The following assigns a System.DateTime value to the PowerShell automated property.
1
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
2
$item.__Created = [DateTime]::Now
3
$item.__Created
4
5
# Tuesday, March 17, 2020 12:00:00 PM
Copied!
Great we've just changed it! Our property handlers take care of all the necessary usages of .Editing.BeginEdit and .Editing.EndEdit. This method can be applied for a variety of field types such as GeneralLink and Image.
To provide an example – I’ve extended my home with additional fields as follows:
Extended Sample Item
Example: The following assigns an image to the Image field.
1
$homeItem = Get-Item -Path "master:/content/home"
2
$homeItem.Image = Get-Item -Path "master:\media library\logo"
Copied!
Easy enough, isn't it? Let SPE detect the field type for you and worry about what to call! Now let's assign a content item to GeneralLink.
Example: The following assigns a content item to a GeneralLink field.
1
$homeItem = Get-Item -Path "master:/content/home"
2
$homeItem.GeneralLink = Get-Item -Path "master:\content\home-away-from-home"
Copied!
What about fields that accept lists of items? We've got your back here as well.
Example: The following assigns all children of /sitecore/content/ item to the ItemList field.
1
$homeItem = Get-Item -Path "master:/content/home"
2
$homeItem.ItemList = Get-ChildItem -Path 'master:\content\'
Copied!
Let's see how our item looks in the Content editor after all the assignments that we've just performed:
ItemList Assignment
Great! Looks like it worked.
Those little improvements make your scripts much more succinct and understandable. Try it for yourself!

When not to use the automated properties?

As with every rule there is an exception to this one. Those automated properties perform the $item.Editing.BeginEdit() and $item.Editing.EndEdit() every time which results in saving the item after every assignment. Assigning multiple properties on an item this way might be detrimental to the performance of your script. In such cases you might want to call $item.Editing.BeginEdit() yourself before modifying the item. Subsequently call the $item["field name"] = "new value" for each property modify. Finally end with the $item.Editing.EndEdit().
Choosing this way is situational and will usually only be required if you're working with a large volume of data. In those cases you might also want to introduce the Sitecore.Data.BulkUpdateContext technique.
Example: The following sets multiple properties while using the Sitecore.Data.BulkUpdateContext.
1
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
2
foreach($item in Get-ChildItem -Path "master:\content\home") {
3
$item.Editing.BeginEdit()
4
$item["Title"] = "Sample Item"
5
$item["Text"] = "Sample Item"
6
$item.Editing.EndEdit() > $null
7
}
8
}
Copied!
Example: The following generates a relative url to the specified site and assigns to a variable. Because the New-UsingBlock command creates a new closure, you need to return the data to use in a different scope.
1
$site = [Sitecore.Sites.SiteContextFactory]::GetSiteContext("usa")
2
$relativeUrl = New-UsingBlock (New-Object Sitecore.Sites.SiteContextSwitcher $site) {
3
$pageItem = Get-Item -Path "master:" -Id "{50BE527C-7241-4613-A7A9-20D0217B264B}"
4
[Sitecore.Links.LinkManager]::GetItemUrl($pageItem)
5
}
Copied!
Some other classes you may want to use with the New-UsingBlock function:
  • Sitecore.SecurityModel.SecurityDisabler
  • Sitecore.Data.BulkUpdateContext
  • Sitecore.Globalization.LanguageSwitcher
  • Sitecore.Sites.SiteContextSwitcher
  • Sitecore.Data.DatabaseSwitcher
  • Sitecore.Security.Accounts.UserSwitcher
  • Sitecore.Data.Items.EditContext
  • Sitecore.Data.Proxies.ProxyDisabler
  • Sitecore.Data.DatabaseCacheDisabler
  • Sitecore.Data.Events.EventDisabler

Sitecore API

If you have reached this point, then you are clearly a nerd and want to access using the raw Sitecore API.
Example: The following queries all descendants of the media library, filters by size, and wraps with automatic properties.
1
# Get the root node using Get-Item, then a call to Axes.
2
$mediaItemContainer = Get-Item -Path "master:/media library"
3
$items = $mediaItemContainer.Axes.GetDescendants() |
4
Where-Object { [int]$_.Fields["Size"].Value -gt 100000 } | Initialize-Item
Copied!

Copying Items

Copy-Item : to a new destination

You will find yourself one day in need of copying items on a small to large scale. The Copy-Item command will likely meet the need.
Example: The following copies the item to the specified path with a new ID.
1
Copy-Item -Path "master:\content\home\Sample Item\Sample Item 1" -Destination "master:\content\home\Sample Item\Sample Item 2"
Copied!
Note: The item name will match just as you type it in the command. Lowercase name in the destination will result in an item with a lowercase name.
Example: The following transfers the item to the specified path with the same ID.
1
Copy-Item -Path master:\content\Home -Destination web:\content\home -TransferOptions 0
Copied!
Example: The following copies an entire tree of items and maintains the tree structure.
1
$sourceId = "{AF27FAD3-2AF0-4682-9BF7-375197587579}"
2
$destinationId = "{53F94442-555B-4622-B813-A16ED2CAB01B}"
3
$children = Get-ChildItem -Path "master:" -ID $sourceId
4
foreach($child in $children) {
5
$child | Copy-Item -Destination $destinationId -Recurse
6
}
Copied!

Moving Items

Move-Item : to a new destination

There is a always a better way to do something. Moving items en masse is certainly one that you don't want to do by hand. If the destination item exists the moved item will be added as a child. If the destination item does not exist the source item will be renamed when moved.
Example: The following moves the item from one parent to another.
1
Move-Item -Path "master:\content\home\sample item\Sample Item 1" -Destination "master:\content\home\sample item 2\"
Copied!
Example: The following gets an item and moves to a new parent node, along with all the children.
1
Get-Item -Path "master:" -ID "{65736CA0-7D69-452A-A16F-2F42264D21C5}" |
2
Move-Item -Destination "master:{DFDDF372-3AB7-45B1-9E7C-0D0B27350439}"
Copied!

Creating Items

New-Item

Example: The following creates a new item with the specified template.
1
$itemPath = "master:\content\home\sample item\Sample Item 3"
2
New-Item -Path $itemPath -ItemType "Sample/Sample Item"
3
4
Name Children Languages Id TemplateName
5
---- -------- --------- -- ------------
6
Sample Item 3 False {en} {F6F4F7B7-5E72-4C16-9294-218D80ED89E8} Sample Item
Copied!
Example: The following creates a new item with the specified template id and id.
1
$itemPath = "master:\content\home\sample item\Sample Item 4"
2
$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
3
$itemId = "{9459ADDD-4471-4ED3-A041-D33E559BD321}"
4
New-Item -Path $itemPath -ItemType $templateId -ForceId $itemId
5
6
Name Children Languages Id TemplateName
7
---- -------- --------- -- ------------
8
Sample Item 4 False {en} {9459ADDD-4471-4ED3-A041-D33E559BD321} Sample Item
Copied!
Example: The following creates a new item as a child of the specified item.
1
$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
2
$parentItem = Get-Item -Path "master:\" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
3
New-Item -Parent $parentItem -Name "Sample Item 3" -ItemType $templateId
4
5
6
Name Children Language Version Id TemplateName
7
---- -------- -------- ------- -- ------------
8
Sample Item 3 False en 1 {2F71043A-C731-4EC2-BFE4-0604D4D71652} Sample Item
Copied!
Note: The New-Item command was passed to Format-Table -Autosize to improve the formatting.

Removing Items

Remove-Item : permanently

Example: The following removes the item permanently. Proceed with caution.
1
Remove-Item -Path "master:\content\home\sample item\Sample Item 3" -Permanently
Copied!

References

Last modified 8mo ago