Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. $SourcePath = "https://go.microsoft.com/fwlink/?LinkID=809115"
  2. $DestinationPath = "C:\dotnet"
  3.  
  4. $EditionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID').EditionId
  5.  
  6. if (($EditionId -eq "ServerStandardNano") -or
  7. ($EditionId -eq "ServerDataCenterNano") -or
  8. ($EditionId -eq "NanoServer") -or
  9. ($EditionId -eq "ServerTuva")) {
  10.  
  11. $TempPath = [System.IO.Path]::GetTempFileName()
  12. if (($SourcePath -as [System.URI]).AbsoluteURI -ne $null)
  13. {
  14. $handler = New-Object System.Net.Http.HttpClientHandler
  15. $client = New-Object System.Net.Http.HttpClient($handler)
  16. $client.Timeout = New-Object System.TimeSpan(0, 30, 0)
  17. $cancelTokenSource = [System.Threading.CancellationTokenSource]::new()
  18. $responseMsg = $client.GetAsync([System.Uri]::new($SourcePath), $cancelTokenSource.Token)
  19. $responseMsg.Wait()
  20. if (!$responseMsg.IsCanceled)
  21. {
  22. $response = $responseMsg.Result
  23. if ($response.IsSuccessStatusCode)
  24. {
  25. $downloadedFileStream = [System.IO.FileStream]::new($TempPath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)
  26. $copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream)
  27. $copyStreamOp.Wait()
  28. $downloadedFileStream.Close()
  29. if ($copyStreamOp.Exception -ne $null)
  30. {
  31. throw $copyStreamOp.Exception
  32. }
  33. }
  34. }
  35. }
  36. else
  37. {
  38. throw "Cannot copy from $SourcePath"
  39. }
  40. [System.IO.Compression.ZipFile]::ExtractToDirectory($TempPath, $DestinationPath)
  41. Remove-Item $TempPath
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement