# 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 | |
} |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
Windows Server 2016以降のServer Coreで動作する、ハズ。 PowerShell 6.0を使うには、 Enter-PSSession -ComputerName [computername] -Credential [credential] -ConfigurationName "powershell.6.0.0-beta.9" の様に
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
Windows Server 2016以降のServer Coreで動作する、ハズ。
リモートセッションからこのスクリプトを実行すると途中でセッションが切断されるのでエラーが出ますが設定自体は完了しています。
PowerShell 6.0を使うには、
の様に
-ConfigurationName
を指定して接続してください。ConfigurationName
は接続先サーバーで、とコマンドを実行すれば確認できます。