I'm writing a script to show the missing/new items between two content branches. For the target of the comparison, I build an item path and then call Get-Item
on that path to see if there is an equivalent item. The problem is that Get-Item throws an exception if no item is found - I would just like to handle a case of a 'null' item in my script.
#$source is the root path of the source branch
$localPath = $sourceItem.Paths.FullPath.SubString($source.Length)
$targetPath = "master:" + $target + "/" + $localPath
$targetItem = Get-Item $targetPath
The script works in that $targetItem is null if no item is found using $targetPath but I would like to suppress the error message in the script.
Compare-Object
? This may be more efficient for you. Essentially useGet-ChildItem
for both trees and compare two properties (item path such as /sitecore/content/home).