• PowerShell merge arrays
    25 July

    Merge Arrays in PowerShell

    Using + Operator Use + operator to merge arrays in PowerShell. [crayon-66282320d9532327392572/] [crayon-66282320d953c398554750/] We used the sub-expression operator represented by @() to create two separate arrays named $array1 and $array2 (you can also create arrays without using the sub-expression operator). Note that both arrays contained string-type values. Next, we used the + operator to join […]

  • PowerShell remove special characters from String
    14 July

    PowerShell Remove Special Characters from String

    Using Regex.Replace() Method Use the Regex.Replace() method to remove special characters from the specified string in PowerShell. [crayon-66282320daf9e240122883/] [crayon-66282320dafaa561822058/] First, we declared a variable named $str and set its value to a string containing some special characters. Then, we used the Replace() method of the Regex class from the System.Text.RegularExpressions namespace to replace the special […]

  • PowerShell remove header from Output
    14 July

    PowerShell Remove Header from Output

    For this article, we will use a CSV file, you can use your own, but we will be using inputFile.csv containing the following data: [crayon-66282320dbb53772248875/] Removing Header from Imported Data We can use various ways to remove the header from the imported data before further processing in PowerShell. Let’s learn them below. Use -HideTableHeaders Parameter […]

  • PowerShell trim string after character
    29 June

    PowerShell Trim String After Character

    Using Split()Method Use the Split() method to trim the string after the first occurrence of the specified character in PowerShell. [crayon-66282320def5a233344883/] [crayon-66282320def64810379850/] We declared and initialized the $string variable with "Hi! Welcome to Java2Blog! Let's learn." value. Next, we chained the Split() method with the $string variable to split the $string into an array based […]

  • PowerShell find filename by name
    29 June

    PowerShell Find File by Name

    Using Get-ChildItem Cmdlet Use the Get-ChildItem cmdlet with -Path and -Filter parameters to find the specified files and directories in the given path in PowerShell. [crayon-66282320df1e5693465226/] [crayon-66282320df1e9759558739/] The Get-ChildItem retrieves items and child items from one or multiple paths (locations). The -Path parameter is used to specify one or multiple paths to locations; we can […]

  • PowerShell add days to Date
    28 June

    PowerShell Add Days to Date

    Before we start, knowing how dates are stored in PowerShell is essential. Dates are stored as DateTime, which contains both a date and a time. The dates are in the MM/DD/YYYY format. Let’s continue learning different ways to add days to date in PowerShell. Using AddDays() Method Use the AddDays() method to add days to […]

  • PowerSHell add date to filename
    24 June

    PowerShell Add Date to Filename

    if you don’t want to rename the file and just want to change in string format, you can directly jump to join-path section. Using Rename-Item Cmdlet Use the -Rename-Item cmdlet to add date to file in PowerShell [crayon-66282320df6e8012163862/] [crayon-66282320df6ed995340366/] The above code is functioning in the following manner: It first sets the $Filename variable to […]

  • PowerShell get last modified file in directory
    24 June

    PowerShell Get Last Modified File in Directory

    For this article, our working directory will be C:\Test1 containing two files named File1.txt and File2.txt. Using Get-ChildItem along with Sort-Object Cmdlet Use the Get-ChildItem cmdlet with Sort-Object` cmdlet to get last modified file in directory in PowerShell. Sort-Object cmdlet will sort the File object by LastWriteTime property. [crayon-66282320df924916666604/] [crayon-66282320df929634116879/] The code uses the Get-ChildItem […]

  • PowerShell kill process by name
    20 June

    PowerShell Kill Process by Name

    Using Stop-Process Cmdlet Use the Stop-Process cmdlet to kill a process by name in PowerShell. [crayon-66282320dfb28225288032/] The Stop-Process command stops a process by its name. The -Name parameter specifies the name of the process to stop. For example, if you want to stop the notepad program, write Stop-Process -Name "notepad". You can check all running […]