# Azure PowerShellのインストールに苦労した
###### tags: `PDAS`
## Azure PowerShell
Azure Cloud Shellでもできそうだが、Slackのエクスポートデータをクラウドにあげるのが大変なので、ローカルWindowsPCにインストール。
1. 管理者権限でPower Shell起動
2.
```
> Install-Module -Name Az
```
なんだかエラーが出て、インストール中断。
https://github.com/PowerShell/PowerShell
ここから、PowerShellのstable版をインストールしてみる。
stable版はネットワークエラーが出てダウンロードできず。
LTS版を試す。
PowerShell7がインストールされ、通常のPowerShellとは別アプリのようなので、PowerShell7を管理者権限で起動。
```
> Install-Module -Name Az 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
Install-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:9709
Line |
9709 | … talledPackages = PackageManagement\Install-Package @PSBoundParameters
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Package 'Az.Resources' failed to be installed because: End of Central Directory record could not be
| found.
```
やはり同じエラー
[Azure PowerShell Azモジュールインストール時のエラー対応 \- Qiita](https://qiita.com/shingo_kawahara/items/414d0d270ea2b3e857b2)
こちらを参考にエラーを解消していく。
```
> Register-PSRepository -Default
Register-PackageSource: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:11585
Line |
11585 | … $null = PackageManagement\Register-PackageSource @PSBoundParamete …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Module Repository 'PSGallery' exists.
```
これで再度Azure Shellをインストール
```
> Install-Module -Name Az
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
Install-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:9709
Line |
9709 | … talledPackages = PackageManagement\Install-Package @PSBoundParameters
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Package 'Az.Storage' failed to be installed because: End of Central Directory record could not be
| found.
```
また違うエラー。
[Install\-Module \-Name Az \-Repository PSGallery \-Force](https://github.com/Azure/azure-powershell/issues/9940)
を参考に、
```
> Install-Module -Name Az -Repository PSGallery -Force
Install-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:9709
Line |
9709 | … talledPackages = PackageManagement\Install-Package @PSBoundParameters
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Package 'Az.Compute' failed to be installed because: End of Central Directory record could not be
| found.
```
やっぱりエラー。
[PowerShellGetを使用してAzure PowerShellをインストールする\| Microsoftドキュメント](https://docs.microsoft.com/ja-jp/powershell/azure/install-az-ps?view=azps-4.3.0)
こちらにある、「システム上の全てのユーザーにモジュールをインストールするには・・・」ってところのコマンドでうまく行きました。
```
if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
'Az modules installed at the same time is not supported.')
} else {
Install-Module -Name Az -AllowClobber -Scope AllUsers
}
```