I am using PowerShell to copy the value from one column to another in a document library. The source column is the name field. So far I have this script and it works fine.

$web =  Get-SPWeb -Identity http://siteURL
$lista = $web.Lists["test"]
$items = $lista.items
foreach ($item in $items) {
   $value = $item["Name"]
   $item["other column"] = $value

The only bit I am missing is the ability to remove the file extension from the text value of the name column. Do if the value of the name column is "myFile.pdf" then I need the value of other column to be "myFile" Can I split on something? I am 99% certain there will be no filenames with a "." in them other than the one that separates the name and the extension

1 Answer 1


PowerShell is just another .NET language. You can use methods you would normally use in C# or VB. So the simplest solution is:

$item["other column"] = $value.Split('.')[0]

But you are not limited to String methods. You can call static method of System.IO.Path class this way:

$item["other column"] = [System.IO.Path]::GetFileNameWithoutExtension($value)

Of course you should do some required $null checks first.

  • Thanks I did it like this... apologise for the formatting but everytime I hit enter or shift enter the comment is submitted rather than a line break........ $value = $item["Name"] $splitvalue = $value.Split(".") $item["Asset ID"] = $splitvalue[0]
    – Penfold
    Sep 17, 2015 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.