Chirag Nagrekar has Published 465 Answers

How to copy files with the specific extension in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

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

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, ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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 ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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 ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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 ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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 ... Read More

What is Copy-item in PowerShell used for?

Chirag Nagrekar

Chirag Nagrekar

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

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 ... Read More

How to add/merge two hash tables in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

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

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 ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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() ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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["<key>"] = "<value>"We have hash table already created here, $htable = [Ordered]@{EmpName="Charlie";City="New York";EmpID="001"}PS C:\WINDOWS\system32> $htable Name       Value ---- ... Read More

How to create a Hash Table in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 26-Feb-2020 10:09:07

There are several ways to create a Hash Table in PowerShell. We will discuss here the standard method @{} for creating the Hash Table.Using @{} MethodYou can use @{} method to create a hash table. Key-Value pair is separated with the Semi-Colon (;). You can only add unique keys. Duplicate ... Read More

Advertisements