Below is a script that will change the value of URL field from something to something. Script works fine and is safe to run. Now, I would like to output in a txt file the old and new values.. Please help with this.
$webs = Get-SPSite http://<somesitecollection> | get-spweb -limit all | ?{$_.URL -like ‘<somethinghere’}
foreach ($web in $webs)
{
$list = $web.Lists[“<someList>”]
foreach ($item in $list.Items)
{
# Iterate HyperLink fields
foreach ($field in $fields)
{
# Get field value
$fldValue = $item[“URL”]
# Skip if null
if($fldValue -ne $null)
{
$item[“URL”] = $fldValue -replace “<something>”, “<withSomething>”
$item.update()
}
}
}
}
$webs.Dispose()
One more question. Am I disposing of the SPWeb object correctly here? I get an error when it gets to that step in the script, but the script runs fine. Do I need to dispose of the object?
I have a colleague who helped me with this so I am giving credit there as well.. Thanks to Andrea for the assist. She is our SharePoint Developer and my mentor..
Looks good. Now other people can use it when they need it as well 🙂
You could make the value dynamic. If you don’t mind what the new value is, you could use:
$oldValue = “something”
$newValue = $oldValue + “1”
$item[“URL”] = $fldValue -replace $oldValue,$newValue
In above example it would replace “something” with “something1”