Skip to content

FAQ/ Getting Started with PowerShell

Could you tell us the rudimentary part of PowerShell?

Could you teach me how to do it from the beginning?

response

I created a tutorial.
Could you follow the steps below to get an overview?

preparation

  1. Install the following apps on your PC: Get these apps from the Microsoft Store.

    Note

    Windows 10 comes with PowerShell from the beginning, but this time we will not use it, but we will use the above app, which is a newer version and easier to use.

  2. start windows terminal

    • Enter + in the dialog that appears in R wt .
    • Windows Terminal starts.
    • From now on, this app is wt referred to as .

Creating and running scripts

  1. Configure the settings for running the script.

    • Copy and paste the following string wt into .
    1
    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
    • This allows wt you to call scripts from here.
    • This setting remains in effect until you close this window.
  2. Create a script file.

    • Start Notepad (notepad.exe), and then paste the following content:
    1
    echo "こんにちは。"
    
    • C:\temp\helloworld.ps1 Save as.
  3. Run the script file.

    • Copy and paste the following string wt into .
    1
    C:\temp\helloworld.ps1
    

    • こんにちは。 is displayed.

Working with variables in scripts

  1. Copy and paste the following string wt into .

    1
    2
    $name = "DioVISTA"
    echo ($name + "さん、こんにちは。")
    
    - DioVISTAさん、こんにちは。 is displayed.

    Note

    wt If you copy and paste multiple lines into , you get the following warning:

    警告
    複数の行を含むテキストを貼り付けようとしています。このテキストをシェルに貼り付けると、コマンドが予期せず実行される可能性があります。続行してもよろしいですか?

    慣れないうちは、1行ずつコピー&ペーストすることをお勧めします。

Summary

  • In this tutorial, you created and called a PowerShell script. In addition, we used variables.
  • There are several PowerShell samples on this site. They, too, can be saved and recalled by saving the script, as introduced here. Also, rewrite the contents of the variable as needed.

At last

  1. Microsoft official documentation is enriched.

  2. About PowerShell versions

    • As of December 2021, PowerShell has version 5 and version 7.
    • 5 and 7 may move differently.
    • The one I used this time is 7.
    • Windows 10 originally includes 5
    • In the future, the functions and documentation will be enhanced around 7, so this time we decided to use 7 as an exercise.
    • The command to display PowerShell version information is:
      1
      $host.Version
      
  3. About encoding script files

    • If you are using PowerShell 5, specify as the encoding when you save the script file UTF16 . Many modern text editors set the default encodingUTF8 to , so be careful when saving.
    • On the other hand, PowerShell 7's default encoding is UTF8 , so you often don't need to worry about the encoding.

Last update: 2023-03-17