Back Again
I've completed all my tasks except for one: I need to allow for a corrupted homedirectory being unable to be deleted and which could be on a different server to that where the script is running.
My plan was to move the corrupted directory to a different spot on the same server where it exists. This is where I've been tearing my hair out. What is the best method to do such? Below is some trivial testing code. I've tried two options:
Option 1
Code:
$Computer = '.' ; local computer
$to = 'D:\Accounts\Corrupted Accounts\Rubbish'
$from = 'D:\Accounts\Rubbish'
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
? "Error= " + @ERROR + ' : ' + @SERROR + ' at point ' + '1'
$colFolders = $objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Name = '" + $from + "'")
? "Error= " + @ERROR + ' : ' + @SERROR + ' at point ' + '2'
For Each $objFolder in $colFolders
$result = $objFolder.Rename($to)
? "Error= " + @ERROR + ' : ' + @SERROR + ' at point ' + '3'
Next
but this returns an empty collection as the third error line never appears and the folder doesn't get moved.
Option 2 (which works)
Code:
$objFSO = CreateObject("Scripting.FileSystemObject")
$to = 'D:\Accounts\Corrupted Accounts\Rubbish'
$from = 'D:\Accounts\Rubbish'
$objFSO.MoveFolder($from, $to)
I'd really like to know why Option 1 doesn't work. Also, can FSO be used to bind to a folder on another server? if so, how do you write to path to the folders when it is on another server?