Tuesday, July 14, 2015

Move files from one location to another using PowerShell

Move files from one location to another using PowerShell

--this move the files one location to another and do not copy the file whcih is active
Set-Location C:
Get-ChildItem C:\Temp\Source\*.txt |
    Sort-Object LastWriteTime -Descending |
    Select-Object -Skip 1 -ExpandProperty FullName |
    Move-Item -Destination C:\Temp\Target


---just copes the files but doesnt delet the source files
powershell.exe -command "& { ls C:\Temp\Source\*.txt | sort LastWriteTime -desc | select -skip 1 -expand FullName | mv -dest C:\Temp\Target }"



---moves the files
$file = "C:\temp\source" ## this will be your backup file folder
$archive = "C:\temp\Target\" ## this will be your destination folder
foreach ($file in gci $file -include *.txt -recurse)
{
Move-Item -path $file.FullName -destination $archive ## Move the files to the archive folder

}

we can use any script accordingly to our needs and keep in a job and schedule as needed 

No comments:

Post a Comment

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...