Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Obsolete]Nano ServerにPowerShell 6.0をインストールするスクリプト
& {
# configurations
$VersionNo = 16
$PSInstaller = [PSCustomObject]@{
Uri = "https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.$VersionNo/PowerShell_6.0.0-alpha.$VersionNo-win10-win2016-x64.zip";
OutFile = Join-Path $env:TEMP "powershell-6.0.0-alpha.$VersionNo.zip";
Sha256 = "1AA8F34E640996961BB1D63BE5563502B9944F47D5B20995AAF3C95785965590";
Destination = "C:\Program Files\PowerShell\6.0.0.$VersionNo";
VersionTag = "6.0.0-alpha.$VersionNo"
}
$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
function Invoke-Download([string]$Uri, [string]$OutFile) {
Write-Host "Downloading $Uri ..." -ForegroundColor Green
Write-Host " Destination : $OutFile" -ForegroundColor Green
Add-Type -AssemblyName System.Net.Http
try {
$client = New-Object System.Net.Http.HttpClient
$response = $client.GetAsync($Uri).Result
$hstream = $response.Content.ReadAsStreamAsync().Result
$fstream = [System.IO.File]::Create($OutFile)
$hstream.CopyTo($fstream)
$fstream.Flush()
} finally {
$fstream.Close()
$hstream.Dispose()
$response.Dispose()
}
}
Invoke-Download -Uri $PSInstaller.Uri -OutFile $PSInstaller.OutFile
Invoke-Download -Uri $RemotingInstaller.Uri -OutFile $RemotingInstaller.OutFile
# verify and extract zip
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
Write-Host "Install PowerShell..." -ForegroundColor Green
Write-Host "Extracting $($PSInstaller.OutFile) to $($PSInstaller.Destination) ..." -ForegroundColor Green
Expand-Archive -LiteralPath $PSInstaller.OutFile -DestinationPath $PSInstaller.Destination
Write-Host "PowerShell installation complete!" -ForegroundColor Green
# Install PSRemoting
Write-Host "Install PSRemoting endpoint..." -ForegroundColor Green
# Install-PowerShellRemoting.ps1 invokes restarting WinRM Service.
# So, if you run this script in a PSSession, the session disconnected.
[ScriptBlock]::Create("$($RemotingInstaller.OutFile) -PowerShellHome `"$($PSInstaller.Destination)`" -PowerShellVersion `"$($PSInstaller.VersionTag)`"").Invoke()
Write-Host "PSRemoting endpoing configuration complete!" -ForegroundColor Green
}
# BASE64エンコードしたやつ
# $bytes = [System.Text.Encoding]::Unicode.GetBytes((cat .\Install-PS60toNanoServer.ps1 -Raw))
# $encodedCommand = [Convert]::ToBase64String($bytes)
$encodedCommand = 'JgAgAHsADQAKACAAIAAgACAAIwAgAGMAbwBuAGYAaQBnAHUAcgBhAHQAaQBvAG4AcwANAAoAIAAgACAAIAAkAFYAZQByAHMAaQBvAG4ATgBvACAAPQAgADEANgANAAoAIAAgACAAIAAkAFAAUwBJAG4AcwB0AGEAbABsAGUAcgAgAD0AIABbAFAAUwBDAHUAcwB0AG8AbQBPAGIAagBlAGMAdABdAEAAewANAAoAIAAgACAAIAAgACAAIAAgAFUAcgBpACAAPQAgACIAaAB0AHQAcABzADoALwAvAGcAaQB0AGgAdQBiAC4AYwBvAG0ALwBQAG8AdwBlAHIAUwBoAGUAbABsAC8AUABvAHcAZQByAFMAaABlAGwAbAAvAHIAZQBsAGUAYQBzAGUAcwAvAGQAbwB3AG4AbABvAGEAZAAvAHYANgAuADAALgAwAC0AYQBsAHAAaABhAC4AJABWAGUAcgBzAGkAbwBuAE4AbwAvAFAAbwB3AGUAcgBTAGgAZQBsAGwAXwA2AC4AMAAuADAALQBhAGwAcABoAGEALgAkAFYAZQByAHMAaQBvAG4ATgBvAC0AdwBpAG4AMQAwAC0AdwBpAG4A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AHMAZQBzAHMAaQBvAG4AIABkAGkAcwBjAG8AbgBuAGUAYwB0AGUAZAAuAA0ACgAgACAAIAAgAFsAUwBjAHIAaQBwAHQAQgBsAG8AYwBrAF0AOgA6AEMAcgBlAGEAdABlACgAIgAkACgAJABSAGUAbQBvAHQAaQBuAGcASQBuAHMAdABhAGwAbABlAHIALgBPAHUAdABGAGkAbABlACkAIAAtAFAAbwB3AGUAcgBTAGgAZQBsAGwASABvAG0AZQAgAGAAIgAkACgAJABQAFMASQBuAHMAdABhAGwAbABlAHIALgBEAGUAcwB0AGkAbgBhAHQAaQBvAG4AKQBgACIAIAAtAFAAbwB3AGUAcgBTAGgAZQBsAGwAVgBlAHIAcwBpAG8AbgAgAGAAIgAkACgAJABQAFMASQBuAHMAdABhAGwAbABlAHIALgBWAGUAcgBzAGkAbwBuAFQAYQBnACkAYAAiACIAKQAuAEkAbgB2AG8AawBlACgAKQANAAoAIAAgACAAIABXAHIAaQB0AGUALQBIAG8AcwB0ACAAIgBQAFMAUgBlAG0AbwB0AGkAbgBnACAAZQBuAGQAcABvAGkAbgBnACAAYwBvAG4AZgBpAGcAdQByAGEAdABpAG8AbgAgAGMAbwBtAHAAbABlAHQAZQAhACIAIAAtAEYAbwByAGUAZwByAG8AdQBuAGQAQwBvAGwAbwByACAARwByAGUAZQBuAA0ACgB9AA0ACgA='
powershell.exe -EncodedCommand $encodedCommand
@stknohg

This comment has been minimized.

Copy link
Owner Author

commented Feb 28, 2017

PowerShell 6.0を使うには

Enter-PSSession -ComputerName [nanoserver] -Credential [credential] -ConfigurationName "powershell.6.0.0-alpha.16"

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

@stknohg

This comment has been minimized.

Copy link
Owner Author

commented Oct 26, 2017

Windows Server ver.1709からNano Serverがコンテナ専用になったため、本スクリプトは最新のNano Serverでは意味がなくなりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.