Sitecore SPE scripts

Find the item that have invalid value

function CheckItemFields{
Param ([Sitecore.Data.Items.Item]$item)

$item.Fields.ReadAll()

$invalidFields = $item.Fields | where-object Value -Match 'Fish' # the invalid value

if($invalidFields){
write-host ($invalidFields | select-object -Property name)
write-host $item.Paths.FullPath
}
}

Get-ChildItem -Path "master:\sitecore\content\home" -Recurse | foreach-object {CheckItemFields $_}


Remove HTML tag from a field

Get-ChildItem -Path "master:\sitecore\content\home" -Recurse | foreach-object {
$lb = $_["Listing"]
IF(-not [string]::IsNullOrEmpty($lb)){
$lb = $lb -replace '<p>',''
$lb = $lb -replace '</p>',''
$lb = $lb -replace '<br>',''
$lb = $lb -replace '<br/>',''

$_.Editing.BeginEdit()
$_["Listing"] = $lb
$_.Editing.EndEdit()
}
}

 Export User

Check https://doc.sitecorepowershell.com/appendix/security/get-user for the detail of Get-User cmdlet


Get-User -Filter '*' | Select -Property @{n="Email";e={$_.Profile.Email}},@{n="First name";e={$_.Profile.GetCustomProperty("FirstName")}},
@{n="Last name";e={$_.Profile.GetCustomProperty("LastName")}},@{n="Phone";e={$_.Profile.GetCustomProperty("Phone")}},@{n="Gender";e={$_.Profile.GetCustomProperty("Gender")}},@{n="Birth Date";e={$_.Profile.GetCustomProperty("Birth Date")}} | Export-CSV -Path "$apppath\users.csv"

Download-File "$apppath\users.csv"

Remove-Item "$apppath\users.csv"