Software & Coding Articles

Page 73 of 83

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

Chirag Nagrekar
Chirag Nagrekar
Updated on 12-Mar-2020 15K+ 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
Chirag Nagrekar
Updated on 12-Mar-2020 8K+ 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

Read More

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

Chirag Nagrekar
Chirag Nagrekar
Updated on 12-Mar-2020 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
Chirag Nagrekar
Updated on 12-Mar-2020 403 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
Chirag Nagrekar
Updated on 26-Feb-2020 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

Read More

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

Chirag Nagrekar
Chirag Nagrekar
Updated on 26-Feb-2020 20K+ 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

What is Hash Table in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 26-Feb-2020 679 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 create PowerShell alias permanently?

Chirag Nagrekar
Chirag Nagrekar
Updated on 14-Feb-2020 4K+ Views

PowerShell alias can be created permanently by 2 methods below.a) Import / Export AliasTo export all the aliases, you need to use Export-Alias cmdlet. When you use this command it will ask you the path for the file to import.To export the newly created alias, you need to give alias name and the name for the export, so later you can import it with the same name.In the below example, we have created alias name Edit for the Wordpad and we will export all the aliases with the name Alias1, so the newly created alias will also be stored and ...

Read More

How to get all the aliases in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 14-Feb-2020 466 Views

In PowerShell, you will get all the alias and their commands using Alias: drive as shown below.Dir Alias:OutputHere, Alias: is the drive but surprisingly you will not find it in your operating system. This is the virtual drive and there are other virtual drives as well. You can list all the virtual drives using the below command.Get-Alias will provide the same result.The above output provides the individual alias and their commands for it. But to group them based on their cmdlets, you need to use Group-Object command.Dir Alias: | Group-Object DefinitionOutputYou will see in the output that aliases are listed ...

Read More

How to get/resolve the command from the alias in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 14-Feb-2020 436 Views

To resolve the command name from given alias, you need to use the below command.$Alias:AliasNameFor example, $Alias:dirOR$Alias:lsOutputGet-ChildItemThis means the above commands will provide the same result. For example, the output of the below commands would remain the same.Get-ChildItem C:\ Dir C:\ ls COutputYou can also use Get-Alias to resolve the alias name. For example, Get-Alias -Name dirGet-Alias -Name lsUntil now we need to remember alias name to get the command and we were running individual commands to get the Alias and its command. It is possible to get all the alias names for the given command. To get all aliases ...

Read More
Showing 721–730 of 825 articles
« Prev 1 71 72 73 74 75 83 Next »
Advertisements