0

Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”

$siteUrl = “https://sharepoint/sites/site1/site2/site3/”

$password = Read-Host -Prompt “Enter password” -AsSecureString

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials(“me@domain.com”, $password)

$ctx.Credentials = $credentials

$rootWeb = $ctx.Web

$list = $rootWeb.Lists.GetByTitle(“My Docs”)

$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(1000, ‘Title’)

$items = $list.GetItems($query)

$ctx.Load($items)
$ctx.ExecuteQuery()

$count = $items.Count – 1

write-Host “$count items found.”

$count = $items.Count – 1

for($intIndex = $count; $intIndex -gt -1; $intIndex–)
{
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_01”, “_JAN20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_02”, “_FEB20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_03”, “_MAR20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_04”, “_APR20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_05”, “_MAY20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_06”, “_JUN20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_07”, “_JUL20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_08”, “_AUG20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_09”, “_SEP20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_10”, “_OCT20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_11”, “_NOV20”)
$items[$intIndex][“FileLeafRef”] = $items[$intIndex][“FileLeafRef”].Replace(“_12”, “_DEC20”)
$item.Update()
$list.Update()
$ctx.ExecuteQuery()
Write-Host $items[$intIndex][“FileLeafRef”].ToString()
}

Write-Host “Done.”

(Visited 35 times, 1 visits today)
Add a Comment