Found 463 Articles for PowerShell

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

15K+ 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

265 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

3K+ 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

14K+ 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

How to create a Hash Table in PowerShell?

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

1K+ Views

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 keys are not accepted.$htable = @{EmpName="Charlie";City="New York";EmpID="001"}OutputName       Value ----       ----- EmpID      001 City       New York EmpName    CharlieHere, you will not get the output in an ordered fashion. To get the ordered output, you need to write [Ordered] ahead ... Read More

What is Hash Table in PowerShell?

Chirag Nagrekar
Updated on 26-Feb-2020 10:06:13

243 Views

Hash table in a PowerShell is constructed with the Key-Value combination. Each key has its own value, so to get the value we need to refer the Key. We don’t need numeric indexing like Array to refer values.This is how the hash table looks like.Name       Value ----       ----- EmpName     Charlie City       New York EmpID       001In the hash table creation, keys and values are separated with Semi-colons (;). In the above example, EmpName, City and EmpID are referred as keys while Charlie, New York ... Read More

How to add/remove values in the array in PowerShell?

Chirag Nagrekar
Updated on 03-Nov-2023 03:03:08

32K+ Views

An array is always a fixed size. To add value to the array, you need to create a new copy of the array and add value to it. To do so, you simply need to use += operator.For example, you have an existing array as given below.$array = 1, 2, 3, 4, 5To add value “Hello” to the array, we will use += sign.$array += "Hello"Now, we will check the output of the array.We have another method to add value to the array. By Add() operation of the array.$array.Add("Hi")When you use the above method to add a variable in the ... Read More

How to create an array in PowerShell?

Chirag Nagrekar
Updated on 14-Feb-2020 06:41:14

2K+ Views

To create or declare an array in PowerShell, there are few methods.You can directly assign values to the variable and separate it by comma (, ) and that variable becomes the variable.For example, $a = "Apple", "Dog", "Cat", "Banana", "Camel"$a is now an array. To access the variable you can use the Indexing method. The first value will be stored at 0, second at 1 and so on.$a[0] will give the output “Apple”, $a[1] will give the output “Dog” and so on. Negative indexing also works in the array. -1 is the last index, -2 is the second last and ... Read More

Advertisements