LoginSignup
7
7

More than 5 years have passed since last update.

macOS High Sierra で Azure PowerShell 環境を構築する

Posted at

はじめに

macOS を使うお客さんに結構気軽にAzure CLI使ってくださいとか言っていたのですが、Azure PowerShell のほうがサンプルがあったりすることも多く、読み替えがストレスに感じることも少なからずあることに気づいてしまった。
この記事では、Azure PowerShell を macOS High Sierra で使うために実施した内容について備忘録がてら残しておきます。
本情報の内容(添付文書、リンク先などを含む)は、作成日時点でのものであり、予告なく変更される場合があります。

実際の手順

前提事項

ドキュメントInstall and configure Azure PowerShell on macOS and Linuxに下記の記載があります。

Note:At this time, both PowerShell Core v6 and Azure PowerShell for .NET Core are still in beta. Support for these products is limited. If you have problems or discover bugs, please file Issues in GitHub.
Issues for PowerShell Core v6
Issues for Azure PowerShell

抄訳:
現在では、PowerShell Core v6 および、Azure PowerShell for ,NET Core はベータのため、サポートされている機能は制限されています。もし、問題やバグの発見をされたら、GitHubのIssueに登録してください。

現在はベータの製品ですので、思い通りに動作しないこともありますが、レポートあげることによって将来よりよい製品にしていける可能性があるというものです。

PowerShell Core v6 をインストールする

macOS のドキュメントはSierra(10.12)の記載のみです。Homebrewを使用する方法と直接ダウンロードする方法が記載されていますが、今回は推奨お手軽のHomebrewを使用する方法をサポート外構成のHigh Sierra (10.13)で実施しました。
実際はHomebrew Cask で実行しています。インストール用のバイナリが

Terminal からこんな感じ。

Mihos-MacBook:~ miyamam$ brew tap caskroom/cask
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
futhark                                 libdill                                 libsbol
==> Updated Formulae
angular-cli         dartsim             gecode              irssi               mdcat               rustup-init
aqbanking           ddrescue            git                 jfrog-cli-go        metricbeat          s-nail
awscli              diamond             glpk                joplin              ocaml               sceptre
bareos-client       dmd                 gnutls              juju                ocaml-num           simg2img
bazel               dnscrypt-wrapper    go                  just                ocamlsdl            singular
binaryen            dub                 godep               kallisto            ocrmypdf            stlink
blast               emscripten          gomplate            knot-resolver       opendetex           supervisor
buildapp            flow                googler             leptonica           osm2pgrouting       taisei
c-ares              fluent-bit          grakn               libpqxx             pandoc-citeproc     typescript
cimg                fn                  gtk+3               lumo                pdns                urdfdom
clhep               forego              gutenberg           lzip                pipenv              vala
console_bridge      freetds             heroku              magic-wormhole      qemu                vdirsyncer
coreos-ct           gdnsd               hugo                mas                 rust                xtensor

==> Tapping caskroom/cask
Cloning into '/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask'...
remote: Counting objects: 4016, done.
remote: Compressing objects: 100% (3990/3990), done.
remote: Total 4016 (delta 33), reused 704 (delta 22), pack-reused 0
Receiving objects: 100% (4016/4016), 1.37 MiB | 1.56 MiB/s, done.
Resolving deltas: 100% (33/33), done.
Tapped 0 formulae (4,025 files, 4.3MB)
Mihos-MacBook:~ miyamam$ brew cask install powershell
==> Creating Caskroom at /usr/local/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password:
==> Caveats
A OpenSSL-backed libcurl with GSSAPI is required for custom handling
of certificates and default credentials for web requests.
This is rarely needed, but you can install it with
  brew install curl --with-openssl --with-gssapi
See https://github.com/PowerShell/PowerShell/issues/5638

==> Satisfying dependencies
All Formula dependencies satisfied.
==> Downloading https://github.com/PowerShell/PowerShell/releases/download/v6.0.1/powershell-6.0.1-osx.10.12-x64.pkg
######################################################################## 100.0%
==> Verifying checksum for Cask powershell
==> Installing Cask powershell
==> Running installer for powershell; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
==> installer: Package name is PowerShell - 6.0.1
==> installer: Installing at base path /
==> installer: The install was successful.
🍺  powershell was successfully installed!
Mihos-MacBook:~ miyamam$ 

将来のために書いておくと、ドキュメントにはアップデート時の手順が書いてあります。
現状、Caskの問題により再インストールすることになるという注意書きも。

brew update
brew cask reinstall powershell

Azure PowerShell のインストール

PowerShell Core をインストールしたら、PowerShell Core を起動してからインストールします。
起動時のコマンドは、pwshです。

Mihos-MacBook:~ miyamam$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/miyamam> Install-Module AzureRM.NetCore                                                                       

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its 
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A

続いて、AzureRM.Netcore モジュールを読み込みます。

PS /Users/miyamam> Import-Module AzureRM.Netcore                                                                        PS /Users/miyamam> Import-Module AzureRM.Profile.Netcore     

動作確認をします。Login-AzureRMAccountでログインします。(az loginと同じ要領です。)

PS /Users/miyamam> Login-AzureRMAccount                                                                                 WARNING: To sign in, use a web browser to open the page https://aka.ms/devicelogin and enter the code ...snip... to authenticate.                                                                                                                                                                                                                                                                                                                                                                Account          : ...snip...                                                                                 SubscriptionName : ...snip...                                                                                     
SubscriptionId   : ...snip...
TenantId         : ...snip...
Environment      : AzureCloud

動いた。ということで、インストールはできたようです。

 参考リンク

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7