[wget4nano.ps1] (2016/5/:TP5でも使えるように簡単にしました Test-Nano Function とっちゃいました)
#
# Most of the code included in this script is the copy from
# https://aka.ms/tp4/Install-ContainerHos
#
param(
[string]
[ValidateNotNullOrEmpty()]
$Uri,
[string]
[ValidateNotNullOrEmpty()]
$OutFile
)
$SourcePath = $Uri
$DestinationPath = $OutFile
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.Timeout = New-Object System.TimeSpan(0, 30, 0)
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new()
$responseMsg = $client.GetAsync([System.Uri]::new($SourcePath), $cancelTokenSource.Token)
$responseMsg.Wait()
if (!$responseMsg.IsCanceled)
{
$response = $responseMsg.Result
if ($response.IsSuccessStatusCode)
{
$downloadedFileStream = [System.IO.FileStream]::new($DestinationPath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream)
$copyStreamOp.Wait()
$downloadedFileStream.Close()
if ($copyStreamOp.Exception -ne $null)
{
throw $copyStreamOp.Exception
}
}
}
使い方は...# Most of the code included in this script is the copy from
# https://aka.ms/tp4/Install-ContainerHos
#
param(
[string]
[ValidateNotNullOrEmpty()]
$Uri,
[string]
[ValidateNotNullOrEmpty()]
$OutFile
)
$SourcePath = $Uri
$DestinationPath = $OutFile
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.Timeout = New-Object System.TimeSpan(0, 30, 0)
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new()
$responseMsg = $client.GetAsync([System.Uri]::new($SourcePath), $cancelTokenSource.Token)
$responseMsg.Wait()
if (!$responseMsg.IsCanceled)
{
$response = $responseMsg.Result
if ($response.IsSuccessStatusCode)
{
$downloadedFileStream = [System.IO.FileStream]::new($DestinationPath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream)
$copyStreamOp.Wait()
$downloadedFileStream.Close()
if ($copyStreamOp.Exception -ne $null)
{
throw $copyStreamOp.Exception
}
}
}
.\wget4nano.ps1 -uri <URL> -outfile <ファイルパス>
[<- Nano Server TP4 まとめ]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。