Chirag Nagrekar has Published 465 Answers

How to manipulate Date in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Mar-2020 07:08:36

To add/remove date from the date string you need to use AddDay() method. For example, We need to add 6 days to the current date.(Get-Date).AddDays(6) 25 March 2020 22:40:36To go back to the specific number of days, the same AddDays() method will be used but the numbers are negative. For example, ... Read More

How to format date string in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Mar-2020 07:05:50

By default the when you run the (Get-Date) cmdlet, its output is in the below format.PS C:\WINDOWS\system32> Get-Date 18 March 2020 22:56:18You can format the above output in the various format supported by PowerShell.Examplesd – Short date pattern.PS C:\WINDOWS\system32> Get-Date -Format d 18-03-2020D – Long date patternPS C:\WINDOWS\system32> Get-Date -Format D 18 ... Read More

How to check if the date is adjusted by Daylight saving time using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Mar-2020 06:57:02

To check if the date is adjusted by the daylight savings you need to use the function IsDayLightSavingTime() of the Get-Date cmdlet.PS C:\WINDOWS\system32> (Get-Date).IsDaylightSavingTime() FalseTo know more about DST, check the link below.http://www.webexhibits.org/daylightsaving/b.html

Explain Get-Date function in PowerShell.

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Mar-2020 06:52:48

Get-Date function in PowerShell is to get the current system date and time. For example, when you type simply Get-Date, the output will be, Get-DatePS C:\WINDOWS\system32> Get-Date 18 March 2020 19:17:03When you check the type of the (Get-Date) function, it is DateTime.(Get-Date).GetType() PS C:\WINDOWS\system32> (Get-Date).GetType() IsPublic IsSerial    Name   ... Read More

How to convert the Integer variable to the string variable in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Mar-2020 06:48:35

To convert the integer variable to the string variable, you need to use the explicit conversion or the functional method. In the below example, we are assigning an integer value to the variable $X.$x = 120 $x.GetType().NameNow when you check the data type of that variable, it will be Int32.To ... Read More

How to get the variable data type in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Mar-2020 06:42:48

There are different data types exist for the variable like Byte, Int32, Float, String, etc. To get the variable type, we need to use the GetType() method.Example$x = 10 $x.GetType()OutputIsPublic IsSerial Name    BaseType -------- -------- ----    -------- True     True     Int32   System.ValueTypeTo get ... Read More

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

Chirag Nagrekar

Chirag Nagrekar

Updated on 16-Mar-2020 07:53:22

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

How to search in the file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 16-Mar-2020 07:51:34

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

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

Chirag Nagrekar

Chirag Nagrekar

Updated on 16-Mar-2020 07:50:22

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

How to count the total number of lines in the file in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 16-Mar-2020 07:48:50

To count the total number of lines in the file in PowerShell, you first need to retrieve the content of the item using Get-Content cmdlet and need to use method Length() to retrieve the total number of lines. An example is shown below.Example(Get-Content D:\Temp\PowerShellcommands.csv).LengthOutputPS C:\WINDOWS\system32> (Get-Content D:\Temp\PowerShellcommands.csv).Length 5727Read More

Advertisements