I have saved $item.ModerationInformation.Status
information in HashTable $DeletedItemsIDs
and recycled list items. After That I restored items from recycle bin and assign saved ModerationStatus information back to items, but items restored with "Pending" status. Whats wrong with this Powershell code? I can see the correct saved Moderation status info in variable $deleteditemId.Value
// Saving Modeartion status info
$DeletedItemsIDs = @{}
foreach($item in $ListItems)
{
$DeletedItemsIDs.Add($item.ID,$item.ModerationInformation.Status)
$DeletedItem = $item.recycle()
$DeletedItems.add($DeletedItem)
}
// I do some stuff here and then restore as
ForEach ($deletedGuid in $DeletedItems)
{
$site_To_AddCT.RecycleBin.Restore($deletedGuid)
$Recount++
}
//Here assigning back moderation status info after restoring
ForEach ($deleteditemId in $DeletedItemsIDs.GetEnumerator())
{
$Pageitem = $PagesLibrary.GetItemById($deleteditemId.Key)
$Pageitem.File.CheckOut()
$Pageitem["ContentTypeId"] = $Global:ctToAdd.Id
$Pageitem.File.CheckIn("CheckIn automatically")
$Pageitem.File.Publish("Published automatically")
$Pageitem.ModerationInformation.Status = $deleteditemId.Value // whats wrong here
$Pageitem.Update()
}