remove folder with certain name in powershell - powershell

I need to copy folders from $Frompath to $topath . Now the folders with same name exists in the topath location. Now I need to replace that files with the new files .How can i copy files from one folder to another when the file already exists in the destination.

Related

How to copy a list of folder names in a folder to text file in Powershell?

I have a folder, folder A in a file path, inside folder A are multiple folders (folder 1, folder 2, folder 3). I want to create a Powershell script that goes to the file path where folder A is, read the names of the folders in it and create a .txt file
Inside the .txt file it would have:
folder 1
folder 2
folder 3
I'm not sure how to do this
(there shouldn't be the extra lines in between each folder name in the .txt file, I just can't figure out how to format it properly
So I figured out the solution to my problem. What I was looking for was:
c:\Windows> Get-ChildItem -Path C:\Users... -Name | Out-File -FilePath C:\Users...\test.txt
This outputs the names of the directories that I put in the path and takes them into the test.txt file

PowerShell - extract contents of a specific folder recursively

I want to extract contents of a folder out of a zip file to a different location using powershell.
zip file: archive.zip
path in zip: mypath (folder contains multiple files and subfolders)
destination: c:\destination
If I extract normally I get the folder created:
Command:Expand-Archive -Path archive.zip -DestinationPath c:\destination
Folder Created: c:\destination\mypath
I want to extract the contents of the folder into c:\destination directly.
If it is a specific requirement with the values mentioned in the OP then this should do the work
$Path='c:\temp\destination';Expand-Archive archive.zip $Path;Move-Item $Path\mypath\* $Path;rm $Path\mypath;

Moving files based on their name and extension to a folder matching the name of the file?

I'm in the process of preparing files for uploading into a content management system and they must be in sequentially numbered folders. Each folder will contain image and data files as .tif and .txt, respectively. Currently all the files are in one directory and the goal is to move each file into its corresponding folder.
I can move the files based on the extension and create a folder that matches using this script:
$files = Get-ChildItem *.tif ; ForEach ($file in $files){$folder = New-Item -type directory -name $file.BaseName; Move-Item $file.FullName $folder.FullName;}
This results in folders containing a single .tif with both the folder and the file having a matching name. This is step one.
I'm stuck on step two. I have to move the .txt files that are currently in the parent directory into the matching folders based on the names. The goal is to have folders containing their matching .tif and .txt files. For example, folder "0001" has "0001.tif" and "0001.txt" inside.
Image of the parent directory with .txt and folders

Powershell script to zip users home folder and move it to share drive

I want to move users home folder to share drive who has left the company but before that I want to ZIP it using powershell script. Could you please suggest me or write me quick powershell script which ZIPs the folder and move to share drive creating a same folder name with zip file also same name in destination folder. For instance if source folder is C:\test and destination is \\share\test\
Thanks in Advance,
There's a few ways to zip a folder:
Creating a zipped/compressed folder in Windows using Powershell or the command line
Creating a new folder is simple:
New-Item c:\folder -type directory
https://technet.microsoft.com/en-us/library/ee176914.aspx
And moving a file is also very simple too:
Move-Item c:\source\file.zip c:\destination
https://technet.microsoft.com/en-us/library/ee176914.aspx

Report folders which have a specific subfolder

I am building a script which I use to deploy files to multiple specific folders.
The destination folders are collected using this part.
$destinations = Get-ChildItem "C:\this\is\*\my\path\"
So my script replaces only if the folder has the subfolders "\my\path\"
If I now check my variable it will return the fullpathes but I only need the folder name. I tried using select -path to show at least only the path but it returned as well the length, mode etc.
my goal is to return only values like this:
folder 1
folder 2
folder 3
I am using powershell 3.0
So if we are checking for folders that have the child structure folder1\folder2 where the parent folder is in C:\Temp then we would do something like this:
$destinations = (Get-Item "C:\Temp\*\folder1\folder2").Parent.Parent.Name
Get-Item "C:\Temp\*\folder1\folder2" would just return System.IO.DirectoryInfo objects for folder2. We take those objects and find their grandparent folders and just return their names only.