Submitted By: Kent Finkle

Uses information in an Excel spreadsheet to rename a specified set of folders.

PowerShell
Edit|Remove
$comments = @'
Script name: Rename-Folders.ps1
Created on: Wednesday, July 04, 2007
Author: Kent Finkle
Purpose: How can I use Windows Powershell to
Use Information in an Excel Spreadsheet to Rename a Set of Folders?
'@
#-----------------------------------------------------
function Release-Ref ($ref) {
([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
[System.__ComObject]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers() 
}
#-----------------------------------------------------
$xl = new-object -comobject excel.application
$xl.Visible = $True
$wb = $xl.Workbooks.Open("C:\Scripts\Test3.xls")
$ws = $wb.Worksheets.Item("Sheet1")
$i = 1
Do {
    $a = $ws.Cells.Item($i, 1).Value()
    $b = $ws.Cells.Item($i, 2).Value()
    $b = $b.split("\")[2]
    Rename-Item -Path $a -newName $b
    $i++
}
While ($ws.Cells.Item($i,1).Value() -ne $null)
$a = Release-Ref($ws)
$a = Release-Ref($wb)
$a = Release-Ref($xl)