Found 989 Articles for Software & Coding

How to copy files/folders to the remote location in the PowerShell?

Chirag Nagrekar
Updated on 12-Mar-2020 07:12:25

3K+ Views

To copy files or folders to or from the remote location, you need to provide the UNC path of the items. For example, here we are going to copy a file from the local computer to a remote computer called Test-PC.Copy-Item D:\Temp\PowerShellcommands.csv -Destination \Test- PC\Sharedpath\PScommands.ps1 -PassThruHere, file PowerShellcommands.csv is copied to the remote computer and renamed it with PSCommands.ps1You can also copy files from the one shared location to another shared location.For example, Copy-Item \Test-PC1\D$\PowerShellcommands.csv -Destination \Test- PC\Sharedpath\PScommands.ps1 -PassThruThere is another way to copy items to the remote location is, you can use the ToSession parameter. To use the ToSesssion ... Read More

How to copy files with the specific extension in PowerShell?

Chirag Nagrekar
Updated on 12-Mar-2020 07:10:12

4K+ Views

To copy the files with the specific extension, you need to use the Get-ChildItem command. Through the Get-ChildItem you first need to retrieve the files with the specific extension(s) and then you need to pipeline Copy-Item command.Here, we need to copy *.txt files from the source to the destination location.First, we will retrieve all the *.txt files available in the source path.ExampleGet-ChildItem D:\Temp\ -Filter *.txtOutputPS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Filter *.txt     Directory: D:\Temp Mode                LastWriteTime         Length Name ----                -------------     ... Read More

How to copy readonly and hidden files/folders in the PowerShell?

Chirag Nagrekar
Updated on 12-Mar-2020 07:06:02

2K+ Views

To copy the readonly and hidden items from one location to another, you need to use the –Force parameter with Copy-Item cmdlet.When you run the command without Force parameter for the readonly/hidden files, you will get the error. An example is given below.ExampleCopy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\OutputPS C:\WINDOWS\system32> Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ Copy-Item : Access to the path 'D:\TempContent\Readonlyfile.txt' is denied. At line:1 char:1 + Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo : PermissionDenied: (D:\Temp\Readonlyfile.txt:FileInfo) [Copy-Item], UnauthorizedAccessException    + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError, Microsoft.PowerShell.Commands.CopyItemCommandWhen you add the –Force parameter in the cmdlet, it can copy the readonly/ hidden files as ... Read More

How to copy folder contents in PowerShell with –Recurse parameter?

Chirag Nagrekar
Updated on 12-Mar-2020 07:02:47

14K+ Views

To copy the contents of the folder to the destination folder in PowerShell, you need to provide the source and destination path of the folder, but need to make sure that you need to use a wildcard (*) character after the source path, so the entire folder content gets copied.If you provide only source folder without (*), only folder name gets copied without its contents. We also need to make sure both source and destination folder exists.ExampleCopy-Item -Path D:\Temp\ -Destination D:\TempContent -PassThruOutputWhen you use the above command, you will see the output will be none, because there is no (*) ... Read More

How to copy multiple files in PowerShell using Copy-Item?

Chirag Nagrekar
Updated on 12-Mar-2020 06:59:09

6K+ Views

To copy the multiple files in PowerShell, you need to separate each file with the comma (,).In the below example, we will copy multiple files from the source to the destination folder D:\TempContent.ExampleCopy-Item .\PowerShellcommands.csv,.\cars.xml -Destination D:\TempContent\ -PassThruOutputPS D:\Temp> Copy-Item .\PowerShellcommands.csv,.\cars.xml -Destination D:\TempContent\ -PassThru     Directory: D:\TempContent Mode                LastWriteTime         Length Name ----                -------------         ------ ---- -a----       20-01-2020     12:10        1148809 PowerShellcommands.csv -a----       07-05-2018     23:00            301 cars.xml

How to copy items from one location to another location using PowerShell?

Chirag Nagrekar
Updated on 12-Mar-2020 06:57:43

16K+ Views

To copy items in PowerShell, one needs to use the Copy-Item cmdlet. When you use the Copy-Item, you need to provide the source file name and the destination file or folder name.In the below example, we will copy a single file from the D:\Temp to the D:\Temp1 location.ExampleCopy-Item -Path D:\Temp\PowerShellcommands.csv -Destination D:\Temp1\ -PassThruOutputPS C:\Windows\System32> Copy-Item -Path D:\Temp\PowerShellcommands.csv -Destination D:\Temp1\ -PassThru     Directory: D:\Temp1 Mode                LastWriteTime         Length Name ----                -------------         ------ ---- -a----       20-01-2020   ... Read More

What is Copy-item in PowerShell used for?

Chirag Nagrekar
Updated on 12-Mar-2020 06:54:35

276 Views

Copy-Item in PowerShell cmdlet is used for copying items from one location to another location in the same namespace. Here, the namespace meaning, you can copy items from files to the different folders but cannot files to the registry or the certificate store.This cmdlet doesn’t delete or cut the item from the source location instead, it copies the item to the destination folder with the same name or the different name.Copy-Item Syntax with parameters in PowerShell is as below.Copy-Item    [-Path]    [-LiteralPath]    [[-Destination] ]    [-Container]    [-Force]    [-Filter ]    [-Include ]    [-Exclude ... Read More

How to add/merge two hash tables in PowerShell?

Chirag Nagrekar
Updated on 26-Feb-2020 10:21:00

4K+ Views

Adding values of the hash table is simple as the adding string. We just need to use the addition operator (+) to merge two hash table values.Here, we have two hash tables: $htable and $htable1.$htable = [Ordered]@{EmpName="Charlie";City="New York";EmpID="001"} $htable1 = [Ordered]@{Fruit='Apple';Color='Red'}We will now add two hash tables,$htable + $htalble1PS C:\WINDOWS\system32> $htable+$htable1 Name       Value ----       ----- EmpName    Charlie City       New York EmpID      001 Fruit      Apple Color      Red

How to clear all values from the Hash table in PowerShell?

Chirag Nagrekar
Updated on 26-Feb-2020 10:18:15

2K+ Views

Hash table in the PowerShell session is created temporarily. It is like a variable, when the session is closed, hash table is deleted automatically. If you want to delete all the values from the hash table at once but retaining the hash table variable, you need to use the Clear() method.We have the hash table below created already.$htable = [Ordered]@{EmpName="Charlie";City="New York";EmpID="001"}PS C:\WINDOWS\system32> $htable Name       Value ----       ----- EmpName    Charlie City       New York EmpID      001To clear the above hashtable, $htable.Clear()If you check the hash table data, it won’t display ... Read More

How to add and remove values to the Hash Table in PowerShell?

Chirag Nagrekar
Updated on 26-Feb-2020 10:15:05

15K+ Views

You can add values to the hash table and remove values from the hash tables. To add the values to the hash table, you need to use the below format.$hash[""] = ""We have hash table already created here, $htable = [Ordered]@{EmpName="Charlie";City="New York";EmpID="001"}PS C:\WINDOWS\system32> $htable Name       Value ----       ----- EmpName    Charlie City       New York EmpID      001We need to add additional key “Dept” in the above hash table with the value “Technical”.$htable['Dept']="Technical"When you check the output of the above Hashtable, you can see the key-value is appended to the table.PS ... Read More

Advertisements