6

I wanted to know better way to reset Display Name to empty using PowerShell scripts.

I have written below script..

$item = Get-Item "/sitecore/content/home"
$item.Editing.BeginEdit()
$item["{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}"] = ""
$item.Editing.EndEdit()

which works but I'm not sure its the correct way or not.

I also tried something like $item[Sitecore::FieldIDs::DisplayName] = "" which doesn't work ..

Please help.

  • I'm using Sitecore 7.5 and Sitecore PowerShell Extensions 4.0.0.0 – Harsh Baid Oct 19 '16 at 11:13
11

You can use this to set it to empty. With this you don't need to wrap the change with BeginEdit and EndEdit

$item."__Display Name" = "" 

You only need the quotes here as there is a space in the name, a field without a space can be accessed like so: $item.MyField

If you actually want to reset the field value, rather than explicitly set it as empty, use:

Reset-ItemField -Item $item -IncludeStandardFields -Name "__Display Name"
  • I'm getting this error The term 'Reset-ItemField' is not recognized as the name of a cmdlet I'm using Sitecore 7.5 and Sitecore PowerShell Extensions 4.0.0.0 – Harsh Baid Oct 19 '16 at 11:13
  • Hmm I think this command was in 4.0, I'm just checking that for you. – Kasaku Oct 19 '16 at 11:18
  • Yes this was in SPE 4.0. How did you confirm the SPE version? Did you use the About icon in the ribbon of ISE? – Kasaku Oct 19 '16 at 11:25
  • I have checked from file properties of Cognifide.PowerShell.dll assembly – Harsh Baid Oct 19 '16 at 11:30
  • 1
    @Harsh and I resolved the issue above which was unrelated to the question in hand, he had a corrupt installation of 4.0 and reinstalling it gave access to the command. – Kasaku Oct 19 '16 at 11:44
3

Try this:

Reset-ItemField -Item $item -Name "__Display Name" -IncludeStandardFields

source: Reset-ItemField docs

2

This should do the trick:

Get-Item "master:/sitecore/content/home" | Reset-ItemField -IncludeStandardFields -Name "__Display Name"

See reference here. The IncludeStandardFields is needed as this field is a Sitecore standard field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.