Copy file and folder in localhost and remote computers by using powershell

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome back to my video if you feel the contents are useful kindly subscribe to my YouTube channel so today we are going to talk about another important commandlet called copy item which is useful for both non-native Power Cell users as well as Powershell users okay so we may get a different scenarios to copy a file to copy a folder copy a folder and content copy a file to the remote computers yes there are different scenarios let me demonstrate all of those one by one as I am showing it on the screen I will give an example from all of these so let us start with a simple copy of file so the commandlet using for copying pile is copy item okay so then we need to provide the path so where the file is present I want to move on a file called script.txt which is present in C Powershell and then script Dot txt so this particular file I want to move to a destination folder so we need to plot the destination and where is the destination e i output okay so this is the simple Commander to copy a particular file from one place to another place so let me copy it and run it so now it is completed so first I will show you inside C drive Powershell script.txt file is processed and I will go to E driver now since I provide a destination as key drive and then output folder and now you can see right the file is copy so in the destination we are given as e output so in this output folder it was saying script.txt file because it is copied from this particular place by using copy item okay so this is all copying a simple file from one place to another place okay so I'll delete it now I'll take this one only as example for many things also so next I will go to copier directory contents so this time I want to copy a directed contents not not the directory for example I can show you inside C drive you can see a folder called or a directory called Powershell inside Powershell these many folders signed text password then now what I will do I want to copy the contents present inside the Powershell folder so this is the folder I want to copy the contents only so contents only I'm going to copy not the folder right let me write the commandlet for that foreign yeah let me write it the same command copy and the command will be the same all the time just we need to make little modification okay so this is the folder name say Powershell I'll just copy the same thing and this time I'll put a astero check here so that it will copy the content whatever present inside the folder asteroid stick indicate indicate all the contents okay then I'll provide the same thing destination I'll use the same as e output copy and paste it and run the same thing okay I will go to e Drive now and then output yes you can see right test1 and skip.xt file are copied from another place to here but if if you open test phone it is empty but actually inside C drive if you go to Powershell and test form some other information with that but you are not seeing it on e Drive why because we are not used the parameter called request so let me provide a recurse parameters to the copy item and execute it and let us see whether it is going to copy the content or not right now you are saying complete empty file right inside output let me go to that again and I'll pass a parameter records okay so that it will copy the subfolders files everything okay you are saying right the files are copied successfully even if you open test you are seeing the content now why because we have given requests okay let me delete and go to again so this is all about copying the direct contents so the next one is copying the directory and also its contents so last time you copied only content this time I will copy the folder as well again the same component as I said copy item path so while providing the path we need to make a little modification right earlier we are given the Stars so that Powershell understood like we want to copy all the price but this time I'll remove the star so I will give only Powershell so that power should understand like okay I want to move the Powershell folder itself Powershell fold itself I want to copy not move okay move is again another different command line okay so I will provide the same thing again let me copy and run okay so if you open the Windows Explorer now so you could have seen Powershell folder first and then the context for that right you can see right let me go back again I will come back to e Drive and if you open output you are saying the Powershell folder now earlier you are directly seeing the contents whatever present inside the Powershell bar this time you are seeing the Powershell folder along with that its contents also project you can see right HR details were present all the things are copied properly so that is how you need to understand while copying the simple file you can use this particular commandlet right if you want to move a Content not the folder then you should use Aster stick and if you want to move fold if you want to copy a folder and its content as well so then use this particular command line okay so as I'm repeating I am just using a copying here not moving anything move it is nothing but moving from one place to another place so when it is moved the first place will be it is empty only so I am repeating I am using copy copy here okay so the first three are completed let me go to remote computer okay right now we are in a local host called host name let me execute we'll see the name emma02 okay now what I will do I want to move this particular file right what you are saying inside C drive and then Powershell and then script.pht okay this file I want to move from my local machine ms0 to my remote computer called dc01 let me show how to do that first I will go to my dc01 server and let us use any data present here let me go to e Drive and output it is completely empty this is my dc2 machine let me sorry dc01 machine let me execute hosting my bad this is 0 1 right so let me go to ms02 and execute the command okay so to connect with any of the remote computers to copy a file so we need to First enable the session with that the commandlet for creating the session is new session new new PS session okay PS nothing but Powershell so the command rate is existed and to which I am going to connect I want to connect with a computer called bc01 Dot so dot com so I'm going to connect with this particular server now and then pass the credential if it's in same domain and trust is everything is fine then only to provide the credential sometimes you may not need to sometimes you didn't have the login right that time you need to provide the green trailer which is having the permission on that machine I will show you how to make that just provide the username here like I want to connect that server by using my Contour domain username put it in a double quote c o n t o conto so is my domain name and the username okay this is the user so it is creating the new passion for your session I'll just put this information in a variable called dollar session so now the session it will get created let me run this so at that time it will ask for the username and it will ask for password let me put the password for instance click on OK so it is connected and now I'll give the copy item Commander to copy it thanks copy item then provide the path it is not ready to manage to review this particular parameter like download path you can directly give it also it will understand Powers you will understand okay you are giving the path here so as I said I want to move this particular file script.txt file from localhost to destination folder I will give it here 0 1 machine also I just created a output folder just to make it easy okay there I want to move this file okay this particular script.txt file from D from ms022 I want to move here sorry I'm just repeating as Momo it is not more it is copy I will just want to copy so it will copy the content from this file to this file you can see so but the only thing which we need to need to do here is we need to provide the session to which session it is going to connect for using this copy item so for that you just provide parameter called two session two session and provide a session name I have given session name as session so I'll just do the same thing so now we are good we have created the session first and then we are using a copy item yes we are good let me run now okay copied run class for the password let me put the password click ok now it is completed I will go to my remote computer dc01 so it has to be copied now I'll go to file explorer and then e-rail then output you are saying right already the file is copied successfully we are on the remote computer now this file is copied from my Local Host so make sure while using or while copying the content from one server to remote server just create a session and provide the session details to copy item so that the copy item will understand and I'll copy the content okay you can see that we are on dc01 server now vc01 this is how you need to copy the content from one server to remote computer okay so we are done with first four and we are left at with only one thing that is using the builders to copy the content okay let me demonstrate what is mean by it so if you go to E trial let me delete all these whatever present here select internet okay so if you notice inside Powershell you are seeing two one five on folder test is the folder and script is the file so what I want so whatever the file name contains t e so I'm applying the filter here so whatever the file containing the name t e only those files should copy by looking at the name only you can tell T is the only tesd1 is The Only Name containing T and this part should be copied so let me write how we can do that so the Commodities I can same copy item and then provide the path so here you should give it like this so this is the path I am going to use instead of typing I'll paste it and then destination is again I'm using same copy and paste it so the only thing which we are going to make the change here is we need to provide a parameter include here so that copy item will understand whatever the things it should include while copying that is include okay I want to give it as p e so whatever the name started with t later later whatever it is but it has to be start with d so only those items it should copy from this Powershell folder to this output folder okay hope the con command is clear let me run select line 12 running okay right now we're in C photo let me go to E and output inside output now we are seeing only one folder called test1 earlier inside output we are seeing to one folder one file just one is one folder along with that we're also seeing another file called Script dot EXT as you can see inside see you right script.txt test one more than that but now we have more only test one by using the filter likewise you can put the condition also while copying the content hope the session is useful let me know if any queries
Info
Channel: Rudresh Reddy
Views: 1,734
Rating: undefined out of 5
Keywords: powershell
Id: 61E5LB5cXq0
Channel Id: undefined
Length: 14min 16sec (856 seconds)
Published: Thu May 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.