mercredi 29 novembre 2017

Copy file to randomly named directory with PowerShell

#copies program directory

copy-item .\iphone -Recurse c:\Users\$env:username -force

#sets file I want to copy to unknown directory name as $file1

C:\Users\$env:username\iphone\.filename = $file1

#sets unknown folder location to $location1 which is a randomly named directory 
#under this subfolder in appdata\Roaming\parentfolder\23761253721536721(random //number) , 
#name is just a string of numbers

Get-ChildItem  C:\Users\$env:username\AppData\Roaming\parentfolder = $location1

//attempts to copy file to location

copy-item $file1 $location1

New to powershell. I'm sure I'm making this harder than it needs to be. This like my 10th script trying to do this and I feel like I'm getting further from the answer. Been on technet looking at examples and just not finding anything for setting the unknown directory path to which I'm trying to copy the file.

If with your answer you wouldn't mind explaining what the code is doing so I can learn I would appreciate it.




Aucun commentaire:

Enregistrer un commentaire