• Check if Hashtable contains key in PowerShell
    06 February

    Check if HashTable Contains Key in PowerShell

    Using ContainsKey() Method To check if HashTable contains a key in PowerShell,Use the if statement with the .ContainsKey() method. $hashTable = @{'Name'='PowerShell'; 'Version'=7.0} $key = 'Name' if($hashTable.ContainsKey($key)){ Write-Host "Key '$key' exists in the hash table." }else{ Write-Host "Key '$key' does not exist in the hash table." } Key 'Name' exists in the hash table. We […]

  • Get Value by Key in PowerShell
    06 February

    PowerShell – Get Value by Key in HashTable

    Getting Single Value by Single Key We can get a single value by a single key in a hash table using the following ways in PowerShell: Indexer Notation .Item() Method Dot Notation Where-Object Cmdlet Use Indexer Notation Use indexer notation represented with square brackets ([]) to get a value by key in HashTable in PowerShell. […]

  • Array of HashTables in PowerShell
    02 February

    PowerShell – Array of HashTables

    Creating an Array of HashTables To create an array of hashtables in PowerShell: Create an array. Create two or more hash tables. Use += operator to add the hash tables (created in the second step) to an array (created in the first step). $arrayOfHashTables = @() $hashTable1 = [ordered]@{ "firstName" = "Mehvish" "lastName" = "Ashiq" […]

  • Write Binary Files in PowerShell
    01 February

    Write Binary Files in PowerShell

    Using Add-Content Cmdlet Use the Add-Content cmdlet to write binary files in PowerShell. $binaryData = [Byte[]] (0x01, 0x02, 0x03, 0x04) Add-Content -Path ".\test.bin" -Value $binaryData -Encoding Byte This script created a new file named test.bin in the current working directory and wrote the binary data to the file. The script will append data to the […]

  • 01 February

    What Does Percent(%) Mean in PowerShell

    Using Percent (%) in Different Contexts Typically the % character is for mod functionality. But in PowerShell, it’s an alias for ForEach-Objectand can be also used as Modulus Operator and an Assignment Operator (%=). Let’s learn each of them below.“ Use Percent(%) as an alias of the ForEach-Object cmdlet in PowerShell We can use % […]

  • 28 January

    PowerShell – Get Number of Lines in CSV File

    Using Get-Content Cmdlet The Get-Content cmdlet can be used in the following ways to get the number of lines in the specified .csv file: Get-Content cmdlet with .Length property Get-Content cmdlet with .Count property Get-Content cmdlet with .ReadCount property Get-Content cmdlet with Measure-Object cmdlet and its -Line parameter Before moving towards the ways mentioned above, […]

  • Read CSV file in PowerShell
    28 January

    Read CSV File in PowerShell

    Using the Import-Csv Cmdlet To read a CSV file in PowerShell, use the Import-Csv cmdlet. $csvFile = "d:\data.csv" Import-Csv -Path $csvFile Country Age Salary Purchased ------- --- ------ --------- France 44 72000 No Spain 27 48000 Yes Germany 30 54000 No Spain 38 61000 No Germany 40 Yes France 35 58000 Yes Spain 52000 No […]

  • Read File into String in PowerShell
    27 January

    Read File into String in PowerShell

    Using the Get-Content Cmdlet We can use the Get-Content cmdlet to read the contents of a file into a string. Use the Get-Content Cmdlet to Read a Single File To read a single file into a string in PowerShell: Use the Get-Content cmdlet with the -Raw parameter to read the file’s contents into a string. […]

  • Get String between two characters in JavaScript
    27 January

    Get String Between Two Characters in JavaScript

    💡TL;DR Use the `substring()` method to get String between two characters in JavaScript. function getSubstring(str, start, end) { char1 = str.indexOf(start) + 1; char2 = str.lastIndexOf(end); return str.substring(char1, char2); } let originalString = "Hello,World!"; let substring = getSubstring(originalString, ',', '!'); console.log(substring); World Here, we got String between `,` and `!` in above example. Using substring() […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.