Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Strings and Arrays in PowerShell Core for Linux

The string data type is probably the most used data type in PowerShell. From displaying messages, prompting for input, or sending data to files, it is almost impossible to write scripts without strings being involved. An array is a data structure designed to store a collection of items. The items can be the same type or different types. This hands-on lab will demonstrate the use of both strings and arrays in PowerShell for Linux.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Jun 15, 2025
Duration
45m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Perform a System Update, Register the MS RedHat Repository, and Install PowerShell
    1. Use the yum command to sync the package index files from their sources via the Internet.
    sudo yum check-update
    
    1. Use the yum command to install the newest versions of all installed packages on CentOS.
    sudo yum update
    
    1. Register the Microsoft RedHat repository.
    curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
    
    1. Install PowerShell.
    sudo yum install -y powershell
    
    1. Start PowerShell.
    pwsh
    
  2. Challenge

    Work with Strings in PowerShell
    1. Create a single quote string 'Hello PowerShell - Today is $(Get-Date)'.
    'Hello PowerShell - Today is $(Get-Date)'
    
    1. Create a double quote string "Hello PowerShell - Today is $(Get-Date)".
    "Hello PowerShell - Today is $(Get-Date)"
    
    1. Show the properties of the double quote string using Get-Member and a pipeline.
    "Hello PowerShell - Today is $(Get-Date)" | Get-Member
    
    1. Create four variables (domain, firstname, lastname, and department) using the following information:
      • Domain - scriptingguru.com
      • First name - John
      • Last name - Smith
      • Department - History
    $domain = 'scriptingguru.com'
    $firstname = 'John'
    $lastname = 'Smith'
    $department = 'History'
    
    1. Using the previously entered variables, derive the following values using the string concatenation operator (+):
      • Name = firstname lastname
      • DisplayName = firstname lastname (department)
      • SamAccountName = firstname.lastname
      • EmailAddress = [email protected]
    $firstname + ' ' + $lastname
    $firstname + ' ' + $lastname + ' (' + $department + ')'
    $firstname + '.' + $lastname
    $firstname + '.' + $lastname + '@' + $domain
    
    1. Once again using the previously entered variables, obtain the same values using PowerShell string expansion.
    "$firstname $lastname"
    "$firstname $lastname ($department)"
    "$firstname.$lastname"
    "$firstname.$lastname@$domain"
    
  3. Challenge

    Work with Arrays in PowerShell
    1. Create an array named A that contains the seven numeric (int) values of 29, 51, 6, 8, 19, 39, and 180.
    $A = 29,51,6,8,19,39,180
    
    1. Create an array named B using the range operator (..) containing the values 1 through 8.
    $B = 1..8
    
    1. Create a strongly-typed 32-bit integer array named ia containing four integers (1148, 2195, 3376, and 9000).
    [int32[]]$ia = 1148,2195,3376,9000
    
    1. Display all the elements in the array $A.
    $A
    
    1. Display the first element in the array $A.
    $A[0]
    
    1. Dispay the third element in the array $A.
    $A[2]
    
    1. Recreate the array $A to contain the numbers 0 through 9 using the range operator (..).
    $A = 0 .. 9
    
    1. Display the last three elements of the array, using negative indexes.
    $A[-1..-3]
    
    1. Exit PowerShell.
    exit
    
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight