快速入門導覽課程

本頁說明如何啟用 Cloud Tools for PowerShell,使用 gcloud CLI 進行驗證,以及執行 PowerShell Cmdlet。

事前準備

操作步驟如下:

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. 以管理員身分執行下列指令,從 PowerShell 指令列安裝 gcloud CLI:
  7. Install-Module GoogleCloud

    使用 gcloud CLI 進行驗證

    Cloud Tools for PowerShell 會使用儲存在 gcloud CLI 中的憑證和設定來啟用 cmdlet。如要使用 cmdlet,請先使用 gcloud CLI 登入:

    1. 在命令提示字元中執行下列指令:

      gcloud init
    2. 使用 Google 使用者帳戶並接受登入選項:

      To continue, you must log in. Would you like to log in (Y/n)? Y

    3. 在您的瀏覽器上,於系統提示時登入 Google 使用者帳戶,按一下「允許」以授予存取 Google Cloud 資源的權限。

    4. 在命令提示字元中,選取您具有 Google Cloud 擁有者、編輯者或檢視者權限的專案:

      Pick a cloud project to use:
      [1] [my-project-1]
      [2] [my-project-2]
      ...
      Please enter your numeric choice:

    執行 PowerShell cmdlet

    進行驗證後,您就可以開始使用 Cloud Tools for PowerShell。請開啟 PowerShell 視窗並嘗試執行以下指令。

    取得目前專案、特定專案或特定值區的所有值區:

    $currentProjBuckets = Get-GcsBucket
    $specificProjBuckets = Get-GcsBucket -Project my-project-1
    $bucket = Get-GcsBucket -Name my-bucket-name

    列出所有與專案關聯的 Compute Engine 執行個體:

    Get-GceInstance -Project my-project-1 |
        Sort Status |
        Format-Table Name, Status -GroupBy Status
    
        Status: RUNNING
    
    Name    Status
    ----    ------
    my-vm-2 RUNNING
    my-vm-3 RUNNING
    
        Status: TERMINATED
    
    Name    Status
    ----    ------
    my-vm-1 TERMINATED

    Cloud Tools for PowerShell 包括 Cloud Storage 的 PowerShell 提供者。此提供者讓您能像在本機檔案系統一樣,使用 cddircopydel 等指令來查看及操作您在 Cloud Storage 的資料。

    如要直接使用提供者,可以從開始功能表上的捷徑啟動 Cloud Tools for PowerShell,即會啟動已載入提供者的 PowerShell 主控台。

    # Navigate to Cloud Storage
    cd gs:\
    # Show the available buckets
    ls
    # Create a new bucket
    mkdir my-new-bucket

    您也可以透過 Import-Module GoogleCloud 匯入 Cloud Tools for PowerShell 模組,即可在任何 PowerShell 工作階段中啟用 Cloud Storage 提供者。

    後續步驟

    您可以查看 Cloud Tools for PowerShell 的 Cmdlet 參考資料,或是使用 PowerShell 內建的說明系統,進一步瞭解特定的 cmdlet。

    Get-Help New-GcsBucket