Windows 10 Powershell move-item destination not accepting variables

  • Thread starter Thread starter rylar717
  • Start date Start date
R

rylar717

I have the following script below in which I am trying to do the following:

1. scan all the folders and sub-folders for OneNote files (*.one, *.onetoc, etc.)

2. Take those files and move them into a temporary folder while noting the source folder at the same time

3. take the same files out of the temporary folder and move them back where they were before.


The whole point of this is to re-hydrate our OneNote files due to some de-duplication challenges we had on our file server. I have gotten the following script to work, but it fails at line 22 as it does not like the -destination variable saying that "specified method not supported." I have tried this using the same format as in line 12 but I need to have a variable for the destination as it is not always static like it is in step 12. Also, I am able to only do this with just *.one files as noted on line 2 but when I add in other file types (such as *.onetoc it does not like that either.


Any Help would be appreciated

Thank you


#this will retrieve all of the OneNote files within a folder and subfolders:

$Sourcefiles=get-childitem"C:\Folder\onenotetest\*.one"-Recurse-Force|%{ $_.FullName }


#this will capture the path of the folder that the OneNote folder resides in:


$sourcefolder=split-path$Sourcefiles


#this creates a temporary folder for the OneNote files to go:


New-item-ItemTypedirectory-Path$sourcefolder-Nametemp1-Force


Pause


#moves OneNotes into temporary folder from source folder:


move-item$Sourcefiles-DestinationC:\Folder\OneNotetest\temp1-Verbose-Force


Pause


#this creates a list of the files that need to be moved back to source folder:


Get-ChildItemC:\Folder\OneNotetest\*.*|Select-Object{$_.fullname} |Export-CsvC:\Folder\OneNotetest\test.csv-NoTypeInformation


Pause


#takes CSV file and will move back files to original location by reading off of CSV File:


$listPath="C:\Folder\OneNotetest\test.csv"

$list=import-csv$listPath|ForEach-Object{

move-item"C:\Folder\OneNotetest\temp1\*.*"-Destination$_."fullname"-Verbose-Force


}


Pause


Continue reading...
 
Back
Top