PowerShell
  • Introduction
  • Chapter1: Write a basic powershell script
    • 1.1.Parameters
  • Chapter2: Remote controlling
    • 2.1.Introduction
    • 2.2.System Requirement
    • 2.3.Environment Setting
    • 2.4.Remote login
    • 2.5.Run remote program
    • 2.6.Remote interaction patterns
  • Chapter3: Some remote interactions for Windows 7\/ 10
    • 3.1.USB throughtput interactions
    • 3.2.mSATA throughtput interactions
    • 3.3.UART-echo interactions
    • 3.4.UART-throughput interactions
    • 3.5.UART-loopback interactions
    • 3.6.Ethernet-IIS interactions
    • 3.7.Ethernet-Wake on LAN interactions
    • 3.8.Ethernet-throughput interactions
    • 3.9.Ethernet-static ip interactions
    • 3.10.Ethernet-VPN interactions
    • 3.11.run once interactions
    • 3.12.Time zone interactions
    • 3.13.Firewall interactions
    • 3.14.Watchdog interactions
    • 3.15.File System interactions
    • 3.16.NTP interactions
    • 3.17.SNMP interactions
    • 3.18.FBWF interactions
    • 3.19.EWF interactions
    • 3.20.UWF interactions
  • Chapter4: Common Type
  • Chapter5: Common Operation
  • Chapter6: Socket Programming
Powered by GitBook
On this page
  • The following items will be introduced in the following section:
  • 1.Parameters

Was this helpful?

Chapter1: Write a basic powershell script

The following items will be introduced in the following section:

  • 1.Parameters

1.Parameters

  • powershell用param來定義參數

    • 例如

        param (
            [string]$price = 100, 
            [string]$ComputerName = $env:computername,    
            [string]$username = $(throw "-username is required."),
            [string]$password = $( Read-Host -asSecureString "Input password" )
            [switch]$SaveData = $false
        )
        write-output "First argument is $price"
        write-output "Second argument is $ComputerName"
        write-output "The True/False switch argument is $SaveData"
    • 呼叫方法可為:

       .\demo.ps1 -ComputerName "\\server64" -SaveData
      • or setting -SaveData to $FALSE:

         .\demo.ps1 -ComputerName "\\server64" -SaveData:$false
  • Parameter Attributes

    • 例如

        [Parameter(Mandatory = $true)] 
      • Mandatory

        • 參數是否必備: $true-設為必備/ $false-設為option

PreviousIntroductionNext1.1.Parameters

Last updated 5 years ago

Was this helpful?