Last active
April 19, 2018 05:23
-
-
Save stknohg/b2ef4be8bc5a5e949aa2f141fe723d46 to your computer and use it in GitHub Desktop.
Windows Server ver.1709(Server Core)にPowerShell 6.0をインストールするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for Windows Server Core | |
& { | |
# configurations | |
$PS_VERSION = "6.0.0-beta.9" | |
$PSInstaller = [PSCustomObject]@{ | |
Uri = "https://github.com/PowerShell/PowerShell/releases/download/v$PS_VERSION/PowerShell-$PS_VERSION-win-x64.msi"; | |
OutFile = Join-Path $env:TEMP "PowerShell-$PS_VERSION-win-x64.msi"; | |
InstallLog = Join-Path $env:TEMP "PowerShell-$PS_VERSION-win-x64-install.log"; | |
Sha256 = "D8A194C8944C4680F27406AC5B341971C546C04279A47C927FAB10D6F5CBFF2A"; | |
Destination = "C:\Program Files\PowerShell\$PS_VERSION"; | |
} | |
$RemotingInstaller = [PSCustomObject]@{ | |
Uri = "https://raw.githubusercontent.com/PowerShell/PowerShell/master/src/powershell-native/Install-PowerShellRemoting.ps1" | |
OutFile = Join-Path $env:TEMP "Install-PowerShellRemoting.ps1"; | |
} | |
# download | |
Invoke-WebRequest -Uri $PSInstaller.Uri -OutFile $PSInstaller.OutFile | |
Invoke-WebRequest -Uri $RemotingInstaller.Uri -OutFile $RemotingInstaller.OutFile | |
# verify | |
if ((Get-FileHash -LiteralPath $PSInstaller.OutFile -Algorithm SHA256).Hash -eq $PSInstaller.Sha256) { | |
Write-Host "Verified SHA256 hash..." -ForegroundColor Green | |
} else { | |
Write-Warning "Invalid SHA256 hash!" | |
return | |
} | |
if (Test-Path -LiteralPath $PSInstaller.Destination) { | |
Write-Warning "$($PSInstaller.Destination) already exists!" | |
return | |
} | |
# Install PowerShell Core | |
Write-Host "Install PowerShell Core..." -ForegroundColor Green | |
Start-Process -FilePath "msiexec.exe" -ArgumentList @('/i', $PSInstaller.OutFile, '/qn', '/l*', $PSInstaller.InstallLog) -Wait -PassThru | |
Write-Host "PowerShell installation complete!" -ForegroundColor Green | |
# Install PSRemoting | |
Write-Host "Install new PSRemoting endpoint..." -ForegroundColor Green | |
# Install-PowerShellRemoting.ps1 invokes restarting WinRM Service. | |
# So, if you run this script in remote session, the session disconnected. | |
[ScriptBlock]::Create("$($RemotingInstaller.OutFile) -PowerShellHome `"$($PSInstaller.Destination)`" ").Invoke() | |
Write-Host "PSRemoting endpoing configuration complete!" -ForegroundColor Green | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windows Server 2016以降のServer Coreで動作する、ハズ。
リモートセッションからこのスクリプトを実行すると途中でセッションが切断されるのでエラーが出ますが設定自体は完了しています。
PowerShell 6.0を使うには、
の様に
-ConfigurationName
を指定して接続してください。ConfigurationName
は接続先サーバーで、とコマンドを実行すれば確認できます。