Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active April 19, 2018 05:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stknohg/b2ef4be8bc5a5e949aa2f141fe723d46 to your computer and use it in GitHub Desktop.
Save stknohg/b2ef4be8bc5a5e949aa2f141fe723d46 to your computer and use it in GitHub Desktop.
Windows Server ver.1709(Server Core)にPowerShell 6.0をインストールするスクリプト
# 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
}
@stknohg
Copy link
Author

stknohg commented Oct 26, 2017

Windows Server 2016以降のServer Coreで動作する、ハズ。
リモートセッションからこのスクリプトを実行すると途中でセッションが切断されるのでエラーが出ますが設定自体は完了しています。

PowerShell 6.0を使うには、

Enter-PSSession -ComputerName [computername] -Credential [credential] -ConfigurationName "powershell.6.0.0-beta.9"

の様に-ConfigurationNameを指定して接続してください。

ConfigurationNameは接続先サーバーで、

Get-PSSessionConfiguration -Name powershell.6.0.0*

とコマンドを実行すれば確認できます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment