Microsoft Technologies Articles

Page 165 of 175

How to convert the content of the file into uppercase or lowercase?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 3K+ Views

To convert the content of the file into the upper case, you need to use the method ToUpper() and to convert into lower case, you need to use ToLower() method.Upper case example(Get-Content D:\Temp\PowerShellaliases.txt).ToUpper()OutputPS C:\WINDOWS\system32> (Get-Content D:\Temp\PowerShellaliases.txt).ToUpper() COMMANDTYPE     NAME                                               VERSION    SOURCE -----------     ----                                               -------    ------ ALIAS         ...

Read More

How to search in the file using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 13K+ Views

To search the content in the file in PowerShell, you need to first get the content from the file using Get-Content command and then you need to add Select-String pipeline command. In the below example, we need to search the lines which contain the Get word.PS C:\WINDOWS\system32> Get-Content D:\Temp\PowerShellaliases.txt | Select-String -Pattern Get Alias           cat -> Get-Content Alias           dir -> Get-ChildItem Alias           gal -> Get-Alias Alias           gbp -> Get-PSBreakpoint Alias           gc -> Get-Content Alias   ...

Read More

How to retrieve a specific number of lines from files in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 1K+ Views

To retrieve the specific number of lines from the beginning or the end of the file, you first need to get the content of the file using Get-Content and then need to pipeline the -First for retrieving the number of files from the beginning and -Last to retrieve the number of lines from the bottom.Check the below example of retrieving the content of the first 10 lines.ExampleGet-Content D:\Temp\PowerShellaliases.txt -First 10OutputPS C:\WINDOWS\system32> Get-Content D:\Temp\PowerShellaliases.txt -First 10 CommandType     Name                                               Version ...

Read More

How to retrieve the content of the file in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 628 Views

To retrieve the content of the file in PowerShell, you need to use Get-Content cmdlet. For example, we are going to retrieve the content of the text file called Aliases.txt from a specific location.ExampleGet-Content D:\Temp\aliases.txtOutputPS C:\WINDOWS\system32> Get-Content D:\Temp\aliases.txt # Alias File # Exported by : admin # Date/Time : 26 January 2020 19:20:24 # Computer : DESKTOP-9435KM9 "foreach", "ForEach-Object", "", "ReadOnly,  AllScope" "%", "ForEach-Object", "", "ReadOnly,  AllScope" "where", "Where-Object", "", "ReadOnly,  AllScope" "?", "Where-Object", "", "ReadOnly,  AllScope" "ac", "Add-Content", "", "ReadOnly,  AllScope" "clc", "Clear-Content", "", "ReadOnly,  AllScope" "cli", "Clear-Item", "", "ReadOnly,  AllScope" "clp", "Clear-ItemProperty", "", "ReadOnly,  AllScope" "clv", "Clear-Variable", "", "ReadOnly,  AllScope" "compare", "Compare-Object", "", "ReadOnly,  AllScope" "cpi", "Copy-Item", "", "ReadOnly,  AllScope" "cpp", "Copy-ItemProperty", "", "ReadOnly,  AllScope" "cvpa", "Convert-Path", ...

Read More

What is Get-Content in PowerShell used for?

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 435 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    [-ReadCount ]    [-TotalCount ]    [-Tail ]    [-Path]    [-LiteralPath]    [-Filter ]    [-Include ]    [-Exclude ]    [-Force]    [-Credential ]    [-Delimiter ]    [-Wait]    [-Raw]    [-Encoding ]    [-AsByteStream]    [-Stream ]    []

Read More

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

Chirag Nagrekar
Chirag Nagrekar
Updated on 16-Mar-2020 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 can simply right click and delete the content.It is also possible to delete the recycle bin content with the PowerShell command with the Clear-Recyclebin cmdlet. This command is introduced in PowerShell 5 and available in newer versions as well.ExampleClear-RecycleBinOutputPS C:\WINDOWS\system32> Clear-RecycleBin Confirm Are you sure you want to perform this action? Performing the operation "Clear-RecycleBin" on target "All of the contents of the Recycle Bin". [Y] Yes  [A] Yes to All ...

Read More

How to use PowerShell Break with the Label.

Chirag Nagrekar
Chirag Nagrekar
Updated on 12-Mar-2020 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++ } Write-Output "Entering to another loop" $j = 1 :mylable while($j -lt 3){    Write-Output "j = $j"    $j++ }Outputi = 1 i = 2 i = 3 i = 4 i = 5 Break statement executed Entering to another loop j = 1 j = 2As you can see in the above example when the value of 5 executed, the block containing label (mylable) is also executed and execution moves to another loop.

Read More

How to use PowerShell Break statement with the Switch command?

Chirag Nagrekar
Chirag Nagrekar
Updated on 12-Mar-2020 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. An example is given below.ExampleSwitch (3,5){    1 {"This is One"}    2 {"This is Two"}    3 {"This is Three"; Break}    4 {"This is Four"}    5 {"This is Five"; Break} }OutputThis is ThreeYou can notice in the above output that second parameter 5 won’t be executed because the 3 has already been executed with the break statement.

Read More

How to use PowerShell Break statement with the While Loop?

Chirag Nagrekar
Chirag Nagrekar
Updated on 12-Mar-2020 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 of the variable $i reaches 5 because the Break statement is executed.You can also use the break in the nested While loop, here we will take two examples of the nested loop. First when the break is placed outer loop and second when the break is placed in the inner ...

Read More

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

Chirag Nagrekar
Chirag Nagrekar
Updated on 12-Mar-2020 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 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
Showing 1641–1650 of 1,744 articles
« Prev 1 163 164 165 166 167 175 Next »
Advertisements