Chirag Nagrekar has Published 394 Articles

What is Get-Content in PowerShell used for?

Chirag Nagrekar

Chirag Nagrekar

Updated on 16-Mar-2020 07:45:32

434 Views

Get-Content cmdlet in PowerShell is useful for retrieving the contents of the file or the function. This cmdlet is introduced in PowerShell 3.0. When a file is read by this cmdlet, it reads one line at a time and finally returns the whole content as a collection of objects.SyntaxGet-Content   ... Read More

How to clear the content of the recycle bin in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 16-Mar-2020 07:42:35

3K+ Views

Recycle bin in Windows operating system is to store the soft-deleted data. Soft deleted data means, data that is not deleted with (SHIFT + DEL) button but simply deleted with DEL button. Each local disk has its own configured recycle bin space.To delete the recycle bin data using GUI, you ... Read More

How to use PowerShell Break with the Label.

Chirag Nagrekar

Chirag Nagrekar

Updated on 12-Mar-2020 07:30:16

926 Views

When the break statement is mentioned with the Label, PowerShell exits to the label instead of exiting the current loop.Example$i = 1 while ($i -lt 10) {    Write-Output "i = $i"    if($i -eq 5){       Write-Output "Break statement executed"       Break :mylable    }    $i++ ... Read More

How to use PowerShell Break statement with the Switch command?

Chirag Nagrekar

Chirag Nagrekar

Updated on 12-Mar-2020 07:28:38

480 Views

In Switch command, when the single value passed and if it matches the condition then the loop gets automatically exited but when there are multiple values passed and if the value matches the first condition and if you want to terminate the loop then you can use the Break statement. ... Read More

How to use PowerShell Break statement with the While Loop?

Chirag Nagrekar

Chirag Nagrekar

Updated on 12-Mar-2020 07:21:53

3K+ Views

You can use the break statement with both the While loop and the Do-While loop.To use the Break with a while loop, see the example below.Example$i = 1 While($i -ne 10){    Write-Output $i    if($i -eq 5){break}    $i++ }Output1 2 3 4 5In the above example, the loop terminates when the value ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

4K+ 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 ... 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

3K+ 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 ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

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

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

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

Chirag Nagrekar

Chirag Nagrekar

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

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

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

Advertisements