Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Working with Variables in PowerShell Core for Linux

You can store all types of values in PowerShell variables. For example, store the results of commands, and store elements that are used in commands and expressions, such as names, paths, settings, and values. This lab will cover the concepts of creating and using variables in PowerShell for Linux.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Apr 24, 2020

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 Creating, Changing, Using, and Removing Variables

    1. Set a variable named MyVar and enter the integers 10, 11, and 12 as values:
    $MyVar = 10, 11, 12
    
    1. Set a variable named Path and enter the path "/home/cloud_user/" as the value:
    $Path = "/home/cloud_user"
    
    1. Set a variable name Process and set the cmdlet Get-Process as the value:
    $Processes = Get-Process
    
    1. Set a variable named Today and set the value as (Get-Date).DateTime as the value:
    $Today = (Get-Date).DateTime
    
    1. Call the variable MyVar and observe the output:
    $MyVar
    
    1. Call the variable Today and observe the output:
    $Today
    
    1. Call the variable Path and observe the output:
    $Path
    
    1. Call the variable Processes and observe the output:
    $Processes
    
    1. Change the value of MyVar to 15,16,17
    $MyVar = 15,16,17
    
    1. Call the variable MyVar and observe the change in the output:
    $MyVar
    
    1. Change the value of MyVar to "The Blue Dog"
    $MyVar = "The Blue Dog"
    
    1. Call the variable MyVar and observe the change in the output:
    $MyVar
    
    1. Clear the variable MyVar using both the Clear-Variable and $null methods":
    Clear-Variable -Name MyVar
    $MyVar = $null
    
    1. Call the variable MyVar and observe the change in the output:
    $MyVar
    
    1. Remove the variable MyVar using the Remove-Variable cmdlet:
    Remove-Variable -Name MyVar
    
    1. Run the cmdlet Get-Variable and verify that MyVar is not in the list of variables:
    Get-Variable
    
    1. Exit PowerShell
    exit
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans