azure サポート エンジニア直伝 ~ powershell 実践活用術 ~

39
Microsoft Tech Summit 2017

Upload: shuheiuda

Post on 21-Jan-2018

1.295 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

Microsoft Tech Summit 2017

Page 2: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 3: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> Get-Profile -Name “Shuhei Uda” | Format-List

名前 : 宇田周平職種 : サポートエンジニア

2015/12 – 2017/11

Azure (IaaS / Networking)

2013/06 – 2015/11

Windows (Hyper-V / RDS / Performance)

Page 4: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 5: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 6: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 7: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

「何もしてないのに壊れました」

「Windows Update したら調子が悪い」

Page 8: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

データのバックアップ・リストア

アプリケーションの再インストール

Page 9: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 10: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 11: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

# 実行ポリシーを設定 (要管理者権限)

Set-ExecutionPolicy RemoteSigned -Force

# Provider を検索

Find-PackageProvider -Force

# Provider を登録

Get-PackageProvider -Name Chocolatey -ForceBootstrap

# パッケージ検索

Find-Package

# インストール

Install-Package -Name Firefox -Force

Install-Package -Name teraterm -Force

Page 12: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 13: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

0

500

1000

1500

2000

2500

3000

Page 14: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 15: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> <Do> - <Something>

(取得) Get - AzureVM

(作成) New - AzureStorageAccount

(変更) Set - AzureRmVirtualNetwork

(削除) Remove - AzureRmPublicIpAddress

# Get-AzureVM: クラシックデプロイモデル向け# Get-AzureRmVM: リソースマネージャーモデル向け

Page 16: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

# まずは Get-AzureRmXXXXから始めましょう!

PS C:\> Get-AzureRmVm

ResourceGroupName Name Location VmSize OsType

----------------- ---- -------- ------ ------

ArmResourceGroup LinuxVM EastAsia Basic_A0 Linux

ArmResourceGroup WindowsVM EastAsia Standard_DS2_v2 Windows

# Get コマンドだけでも様々な情報が取得できますし、# 情報取得のみであれば、環境を壊すこともありません

Page 17: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

$VM = Get-AzureRmVM

$StorageAccount = Get-AzureRmStorageAccount

$VirtualNetwork = Get-AzureRmVirtualNetwork

$ResourceGroup = Get-AzureRmResourceGroup

$PublicIpAddress = Get-AzureRmPublicIpAddress

$NetworkInterface = Get-AzureRmNetworkInterface

$NetworkSecurityGroup = Get-AzureRmNetworkSecurityGroup

$LoadBalancer = Get-AzureRmLoadBalancer

# Get-Command Get-AzureRm* でコマンドの一覧が取得可能

Page 18: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

参考: https://github.com/ShuheiUda/Get-SubscriptionDetails

Page 19: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 20: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

management.core.windows.net

management.azure.com

Resource

Provider

REST API

Endpoint

PowerShell

Console

User

Input

2. HTTP Request

(Get / Put)

1. コマンド入力

(ex. New-AzureRmVM)

4. HTTP Response

(200 / 404 / 503)

3. 内部処理

5. 結果を出力

Page 21: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

management.core.windows.net

management.azure.com

Resource

Provider

REST API

Endpoint

PowerShell

Console

User

Input

2. HTTP Request2. HTTP Request

(Get / Put)

1. コマンド入力

(ex. New-AzureRmVM)

4. HTTP Response

(200 / 404 / 503)

3. 内部処理

5. 結果を出力

• xxxx は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。

• パラメーター名 ‘xxxx' に一致するパラメーターが見つかりません。• パラメーター 'VM' をバインドできません。“xxxx" の値を "System.String" 型から

"Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine" 型に変換できません。

etc…

Page 22: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

management.core.windows.net

management.azure.com

Resource

Provider

REST API

Endpoint

PowerShell

Console

User

Input

2. HTTP Request2. HTTP Request

(Get / Put)

1. コマンド入力

(ex. New-AzureRmVM)

4. HTTP Response

(200 / 404 / 503)

3. 内部処理

5. 結果を出力

• この要求の送信中にエラーが発生しました。

Page 23: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

management.core.windows.net

management.azure.com

Resource

Provider

REST API

Endpoint

PowerShell

Console

User

Input

2. HTTP Request2. HTTP Request

(Get / Put)

1. コマンド入力

(ex. New-AzureRmVM)

4. HTTP Response

(200 / 404 / 503)

3. 内部処理

5. 結果を出力

• InternalError: The server encountered an internal error.Please retry the request.

Page 24: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 25: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 26: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 27: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 28: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 29: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> Get-AzureRmVMBootDiagnosticsData

-Name <VMName> -ResourceGroupName <RGName>

-Windows -LocalPath <C:\logs>

1. 時刻がずれていないかを確認(OS がハングアップしていないか)

2. ネットワーク接続状況を確認

Page 30: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> Get-AzureRmEffectiveNetworkSecurityGroup

-NetworkInterfaceName <NICName>

-ResourceGroupName <RGName>

Page 31: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> Test-AzureRmTraffic.ps1 -VMName VMName

-SourceIPv4Address <IP> -SourcePort <Port>

-DestinationIPv4Address <IP> -DestinationPort <Port>

-Protocol <TCP/UDP> -Direction <Inbound/Outbound>

# ダウンロード先

# https://github.com/ShuheiUda/Test-AzureRmTraffic

Page 32: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 33: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> Test-AzureRmTraffic.ps1 -VMName Name -SourceIPv4Address 203.0.113.4

-SourcePort 65000 -DestinationIPv4Address 10.0.0.4 -DestinationPort 443

-Protocol TCP -Direction Inbound

Access : Deny

Priority : 4096

Name : securityRules/DenyAll

Protocol : All

SourceAddressPrefix : 0.0.0.0/0

SourcePortRange : 0-65535

DestinationAddressPrefix : 0.0.0.0/0

DestinationPortRange : 0-65535

Direction : Inbound

Page 34: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

PS C:\> Test-AzureRmTraffic.ps1 -VMName Name -SourceIPv4Address 203.0.113.4

-SourcePort 65000 -DestinationIPv4Address 10.0.0.4 -DestinationPort 3389

-Protocol TCP -Direction Inbound

Access : Allow

Priority : 1000

Name : securityRules/default-allow-rdp

Protocol : Tcp

SourceAddressPrefix : 0.0.0.0/0

SourcePortRange : 0-65535

DestinationAddressPrefix : 0.0.0.0/0

DestinationPortRange : 3389-3389

Direction : Inbound

Page 35: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

# 本日の資料はこちら http://aka.ms/DEP006

Page 36: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 37: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~
Page 38: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

■ https://www.powershellgallery.com/

https://channel9.msdn.com/Events/de-code/2016/INF-009

https://qiita.com/jca02266/items/a0c71ae90d055ab3893c

■ http://winscript.jp/powershell/

Page 39: Azure サポート エンジニア直伝 ~ PowerShell 実践活用術 ~

https://docs.microsoft.com/ja-jp/powershell/azure/overview

■ https://github.com/Azure/azure-powershell

https://www.syuheiuda.com/?p=3489

■ https://blogs.technet.microsoft.com/jpaztech/