The majority of scripts written with SPE contain one or more of the following commands:
{% tabs %} {% tab title="Get-Item" %}
- Use this to retrieve a single item. Throws an error if the item does not exist.
- Use when Sitecore
query:
orfast:
is required. May return more than 1 item.
Get-Item -Path "master:\content\home"
{% endtab %}
{% tab title="Get-ChildItem" %}
- Use to return an item's children and grandchildren.
Get-ChildItem -Path "master:\content\home" -Recurse
{% endtab %}
{% tab title="New-Item" %}
- Use to create an item based on a specified data template.
New-Item -Path "master:\content\home" -Name "Demo" -ItemType "Sample/Sample Item"
# or
New-Item -Path "master:\content\home" -Name "Demo" -ItemType "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
{% endtab %}
{% tab title="Remove-Item" %}
- Use to delete or recycle an item.
- Accepts items returned by
Get-Item
andGet-ChildItem
.
Get-Item -Path "master:\content\home\delete-me" | Remove-Item
{% endtab %}
{% tab title="Move-Item" %}
- Use to transfer an item from one location to another.
Move-Item -Path "master:\content\home\Demo" -Destination "master:\content\home\Demo1"
{% endtab %}
{% tab title="Copy-Item" %}
- Use to duplicate an item from one location to another.
# Add -PassThru to output the new item
Copy-Item -Path "master:\content\home\Demo1" -Destination "master:\content\home\Demo2"
{% endtab %} {% endtabs %}
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. | – | ✓ | ✓ | – | – | – |
WithParent | Specifies the command should include the parent item. | – | - | ✓ | – | – | – |
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.
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.
{% hint style="info" %} Check out some performance details when using different methods of querying items on the Sitecore StackExchange. {% endhint %}
Example: The following will retrieve the item based on the Sitecore path.
PS master:\> Get-Item -Path master:\content\home
Name Children Languages Id TemplateName
---- -------- --------- -- ------------
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
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#.
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item item = master.GetItem("/sitecore/content/home");
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.
PS master:\> Get-Item -Path master:/content/home -Language da | Format-Table -Property DisplayName, Language, Id, Version, TemplateName
DisplayName Language ID Version TemplateName
----------- -------- -- ------- ------------
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
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.
PS master:\> Get-Item -Path master:/content/home -Language * | Format-Table -Property DisplayName, Language, Id, Version, TemplateName
DisplayName Language ID Version TemplateName
----------- -------- -- ------- ------------
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Notice that the item with language en-US
at its third version.
Example: The following retrieves the item in all languages and versions.
PS master:\> Get-Item -Path master:/content/home -Language * -Version *| Format-Table -Property DisplayName, Language, Id, Version, TemplateName
DisplayName Language ID Version TemplateName
----------- -------- -- ------- ------------
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
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.
Example: The following retrieves the child items in all languages and versions.
PS master:\> Get-ChildItem -Path master:/content -Language * -Version * | Format-Table -Property DisplayName, Language, Id, Version, TemplateName
DisplayName Language ID Version TemplateName
----------- -------- -- ------- ------------
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
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.Workaround found here on Sitecore Stack Exchange.
Example: The following retrieves all items beneath the path /sitecore/content/ with the template of Sample Item.
PS master:\> Get-Item -Path master: -Query "/sitecore/content//*[@@templatename='Sample Item']"
Name Children Languages Id TemplateName
---- -------- --------- -- ------------
Copy of Home True {en, de-DE, es-ES, pt... {503713E5-F9EE-4847-AEAF-DD13FD853004} Sample Item
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Example: The following retrieves all items beneath the path /sitecore/content/ with the template of Sample Item in all versions and languages.
PS master:\> Get-Item -Path master: -Query "/sitecore/content//*[@@templatename='Sample Item']" -Language * -Version * | Format-Table -Property DisplayName, Language, Id, Version, TemplateName -AutoSize
DisplayName Language ID Version TemplateName
----------- -------- -- ------- ------------
Home de-DE {503713E5-F9EE-4847-AEAF-DD13FD853004} 1 Sample Item
Hjem da {503713E5-F9EE-4847-AEAF-DD13FD853004} 1 Sample Item
Home en {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home de-DE {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home pl-PL {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2 Sample Item
Home en-US {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3 Sample Item
Home en-GB {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Hjem da {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1 Sample Item
Example: The following retrieves items matching the query with a specified ISO date and present in a report dialog.
$isoDate = [Sitecore.DateUtil]::ToIsoDate([datetime]::Today)
Get-Item -Path master: -Query "/sitecore/content/home//*[@__Publish > '$($isoDate)']" |
Show-ListView -Property ID,Name,ItemPath
Example: The following returns items with a specific template under a given root using Fast query.
$rootItemId = "{839085D0-C279-47C6-83C9-9CC28E7C111E}"
$rootItem = Get-Item -Path "master:" -ID $rootItemId
$templateId = "{759BA7B1-A216-467E-A37C-2B8D7F1A713C}"
$query = "fast:$($rootItem.ItemPath)//*[@@templateid='$($templateId)']"
Get-Item -Path "master:" -Query $query
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.
$query = "ancestor-or-self::*[@@templatename='Sample Item']"
# Retrieve the items with Axes and a given context item.
$SitecoreContextItem.Axes.SelectItems($query)
# Retrieve the items using the Query class and context item.
# Retrieve the items by prepending the context path to the query.
Get-Item -Path "master:" -Query ("$($SitecoreContextItem.Paths.Path)/$query")
Example: The following retrieves an item by id.
PS master:\> Get-Item -Path master: -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
Name Children Languages Id TemplateName
---- -------- --------- -- ------------
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
The Uri encodes the language and version within the path.
Example: The following retrieves an item by uri.
PS master:\> Get-Item -Path master: -Uri "sitecore://master/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}?lang=en&ver=1"
Name Children Languages Id TemplateName
---- -------- --------- -- ------------
Home True {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
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.
The following examples make use of custom PropertySet for the command Select-Object
.
Example: The following uses the PSSecurity PropertySet.
PS master:\ >Get-Item -Path "master:\content\home" | Select-Object -Property PSSecurity
Name ID __Owner __Security
---- -- ------- ----------
Home {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} sitecore\admin au|sitecore\michael|pe|+item:read|
Example: The following uses the PSTemplate PropertySet.
PS master:\> Get-Item -Path "/sitecore/media library/Images/SPE/kitten1" | Select-Object -Property PSTemplate
Name ID BaseTemplate
---- -- ------------
kitten1 {E58FA823-3CAF-43A1-A5ED-FBE24D3C21B4} {Image, File, Standard template, Media classification...}
Example: The following uses the PSImage PropertySet.
PS master:\> Get-Item -Path "/sitecore/media library/Images/SPE/kitten1" | Select-Object -Property PSImage
Name : kitten1
ID : {E58FA823-3CAF-43A1-A5ED-FBE24D3C21B4}
Alt : Yay
Width : 225
Height : 225
Extension : jpg
Size : 6593
Example: The following uses the PSSchedule PropertySet.
PS master:\> Get-Item -Path "/sitecore/system/Tasks/Schedules/Content Testing/Calculate Statistical Relevancy" | Select-Object -Property PSSchedule
Name : Calculate Statistical Relevancy
ID : {C7533E65-A1D6-4F99-9F12-0AB157299D80}
Schedule : 1900101|19000101|127|1.00:00
Last run : 1/1/0001 12:00:00 AM
Command : {6A79C206-0CD2-4DDD-9DFF-5BF21E002931}
Items :
Example: The following accesses the Image field casted to the type Sitecore.Data.Fields.ImageField
.
$item = Get-Item -Path "master:\content\home"
$item._.Image.Alt
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.
PS master:\> $currentItem = Get-Item -Path 'master:\content\home\sample-item'
PS master:\> $currentItem.PSFields."LinkFieldName"
Anchor :
Class :
InternalPath : /sitecore/content/home/sample-item/
IsInternal : True
IsMediaLink : False
LinkType : internal
MediaPath :
QueryString :
Target :
TargetID : {263293D3-B1B3-4C2C-9A75-6BD418F376BC}
TargetItem : Sitecore.Data.Items.Item
Text : CLICK HERE
Title :
Url :
Root : link
Xml : #document
InnerField : <link linktype="internal" text="CLICK HERE" querystring="" target="" id="{263293D3-B1B3-4C2C-9A75-6BD418F376BC}" />
Value : <link linktype="internal" text="CLICK HERE" querystring="" target="" id="{263293D3-B1B3-4C2C-9A75-6BD418F376BC}" />
Example: The following finds all of the TextField
s and outputs to the console.
$item = Get-Item -Path "master:\content\home"
foreach($field in $item.Fields) {
$item.PSFields."$($field.Name)" |
Where-Object { $_ -is [Sitecore.Data.Fields.TextField] }
}
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
.
PS master:\> Set-ItemProperty -Path master:/content/home -Name "Title" -Value "New Title"
Example: The following sets the title and clears the branch id using .Editing.BeginEdit
and .Editing.EndEdit
methods.
$item = Get-Item master:/content/home
$item.Editing.BeginEdit()
$item["Title"] = "New Title"
$item.BranchId = [Guid]::Empty # or a new value if changing it
$item.Editing.EndEdit()
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.
{% hint style="info" %} 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). {% endhint %}
Example: The following sets the title property using the automated PowerShell property.
$item = Get-Item -Path master:/content/home
$item.Title = "New Title"
$item."Closing Date" = [datetime]::Today
Example: The following changes the display name of the item.
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
$item."__Display name" = "I Like Turtles"
This technique may be used for a wide variety of property types.
{% hint style="info" %} If you need to dynamically reference a property via a property name that is stored in a variable, there are numerous ways to reference it. {% endhint %}
Example:
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
$fieldName = "__Display name"
# All variations will work
Write-Host ($item.$fieldName)
Write-Host ($item."$fieldName")
Write-Host ($item."$($fieldName)")
There are a other hidden gems in automated PowerShell 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.
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
$item.__Created
# Monday, April 07, 2008 1:59:00 PM
Example: The following assigns a System.DateTime
value to the PowerShell automated property.
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
$item.__Created = [DateTime]::Now
$item.__Created
# Tuesday, March 17, 2020 12:00:00 PM
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:
Example: The following assigns an image to the Image field.
$homeItem = Get-Item -Path "master:/content/home"
$homeItem.Image = Get-Item -Path "master:\media library\logo"
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.
$homeItem = Get-Item -Path "master:/content/home"
$homeItem.GeneralLink = Get-Item -Path "master:\content\home-away-from-home"
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.
$homeItem = Get-Item -Path "master:/content/home"
$homeItem.ItemList = Get-ChildItem -Path 'master:\content\'
Let's see how our item looks in the Content editor after all the assignments that we've just performed:
Great! Looks like it worked.
Those little improvements make your scripts much more succinct and understandable. Try it for yourself!
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
.
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
foreach($item in Get-ChildItem -Path "master:\content\home") {
$item.Editing.BeginEdit()
$item["Title"] = "Sample Item"
$item["Text"] = "Sample Item"
$item.Editing.EndEdit() > $null
}
}
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.
$site = [Sitecore.Sites.SiteContextFactory]::GetSiteContext("usa")
$relativeUrl = New-UsingBlock (New-Object Sitecore.Sites.SiteContextSwitcher $site) {
$pageItem = Get-Item -Path "master:" -Id "{50BE527C-7241-4613-A7A9-20D0217B264B}"
[Sitecore.Links.LinkManager]::GetItemUrl($pageItem)
}
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
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.
# Get the root node using Get-Item, then a call to Axes.
$mediaItemContainer = Get-Item -Path "master:/media library"
$items = $mediaItemContainer.Axes.GetDescendants() |
Where-Object { [int]$_.Fields["Size"].Value -gt 100000 } | Initialize-Item
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.
Copy-Item -Path "master:\content\home\Sample Item\Sample Item 1" -Destination "master:\content\home\Sample Item\Sample Item 2"
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.
Copy-Item -Path master:\content\Home -Destination web:\content\home -TransferOptions 0
Example: The following copies an entire tree of items and maintains the tree structure.
$sourceId = "{AF27FAD3-2AF0-4682-9BF7-375197587579}"
$destinationId = "{53F94442-555B-4622-B813-A16ED2CAB01B}"
$children = Get-ChildItem -Path "master:" -ID $sourceId
foreach($child in $children) {
$child | Copy-Item -Destination $destinationId -Recurse
}
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.
Move-Item -Path "master:\content\home\sample item\Sample Item 1" -Destination "master:\content\home\sample item 2\"
Example: The following gets an item and moves to a new parent node, along with all the children.
Get-Item -Path "master:" -ID "{65736CA0-7D69-452A-A16F-2F42264D21C5}" |
Move-Item -Destination "master:{DFDDF372-3AB7-45B1-9E7C-0D0B27350439}"
Example: The following creates a new item with the specified template.
$itemPath = "master:\content\home\sample item\Sample Item 3"
New-Item -Path $itemPath -ItemType "Sample/Sample Item"
Name Children Languages Id TemplateName
---- -------- --------- -- ------------
Sample Item 3 False {en} {F6F4F7B7-5E72-4C16-9294-218D80ED89E8} Sample Item
Example: The following creates a new item with the specified template id and id.
$itemPath = "master:\content\home\sample item\Sample Item 4"
$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$itemId = "{9459ADDD-4471-4ED3-A041-D33E559BD321}"
New-Item -Path $itemPath -ItemType $templateId -ForceId $itemId
Name Children Languages Id TemplateName
---- -------- --------- -- ------------
Sample Item 4 False {en} {9459ADDD-4471-4ED3-A041-D33E559BD321} Sample Item
Example: The following creates a new item as a child of the specified item.
$templateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$parentItem = Get-Item -Path "master:\" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
New-Item -Parent $parentItem -Name "Sample Item 3" -ItemType $templateId
Name Children Language Version Id TemplateName
---- -------- -------- ------- -- ------------
Sample Item 3 False en 1 {2F71043A-C731-4EC2-BFE4-0604D4D71652} Sample Item
Note: The New-Item
command was passed to Format-Table -Autosize
to improve the formatting.
Example: The following removes the item permanently. Proceed with caution.
Remove-Item -Path "master:\content\home\sample item\Sample Item 3" -Permanently