44 [String ]$InstallationType = ' Computer' ,
55 [Switch ]$InstallPwsh7SDK ,
66 [Switch ]$InstallDotnetInteractive ,
7- [Switch ]$InstallNBExtensions ,
8- [Switch ]$UsePipKernel ,
97 [Switch ]$CleanupDownloadFiles ,
108 [String ]$WorkingFolder = $PSScriptRoot
119)
1210$ErrorActionPreference = ' Stop'
1311[Net.ServicePointManager ]::SecurityProtocol = ' tls12, tls11, tls'
1412Push-Location $WorkingFolder
13+ chcp 65001
14+ $OutputEncoding = [System.Console ]::OutputEncoding = [System.Console ]::InputEncoding = [System.Text.Encoding ]::GetEncoding(' utf-8' )
1515$psBoundParameters.Keys | ForEach-Object {
1616 if ($ ($PSBoundParameters .$_.GetType ().Name) -eq ' SwitchParameter' ) {
1717 $paramStrings += " -$_ "
@@ -20,7 +20,7 @@ $psBoundParameters.Keys | ForEach-Object {
2020 $paramStrings += " -$_ $ ( $PSBoundParameters .$_ ) "
2121 }
2222}
23- Write-Verbose " Commandline: `" $PSCommandPath `" $paramStrings "
23+ Write-Host " Commandline: `" $PSCommandPath `" $paramStrings "
2424switch ($InstallationType ) {
2525 { @ (' system' , ' computer' , ' allusers' ) -contains $_ } {
2626 if (-not ([Security.Principal.WindowsPrincipal ][Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ] " Administrator" )) {
@@ -32,15 +32,15 @@ switch ($InstallationType) {
3232 $dataPath = $env: ProgramData
3333 $kernelPath = Join-Path $env: ProgramData ' \Anaconda3\share\jupyter\kernels'
3434 $packagePath = Join-Path $env: ProgramData ' \Anaconda3\Lib\site-packages'
35- $pyTypeOpt = ' --sys-prefix'
35+ # $pyTypeOpt = '--sys-prefix'
3636 [System.Environment ]::SetEnvironmentVariable(' PYTHONUTF8' , 1 , [System.EnvironmentVariableTarget ]::Machine)
3737 }
3838 { @ (' user' , ' justme' ) -contains $_ } {
3939 $condaOpt = ' /InstallationType=JustMe /AddToPath=0 /RegisterPython=1 /NoRegistru=0 /Noscripts=o /S'
4040 $dataPath = $env: UserProfile
4141 $kernelPath = Join-Path $env: AppData ' \jupyter\kernels'
4242 $packagePath = Join-Path $env: USERPROFILE ' \Anaconda3\Lib\site-packages'
43- $pyTypeOpt = ' --user'
43+ # $pyTypeOpt = '--user'
4444 [System.Environment ]::SetEnvironmentVariable(' PYTHONUTF8' , 1 , [System.EnvironmentVariableTarget ]::User)
4545 }
4646 default {
@@ -54,58 +54,45 @@ if ($ProgressPreference -ne 'SilentlyContinue') {
5454 $ProgressPreference = ' SilentlyContinue'
5555}
5656
57- Write-Verbose ' Downloading latest Anaconda...'
57+ Write-Host ' Downloading latest Anaconda...'
5858$links = (Invoke-WebRequest - Uri ' https://www.anaconda.com/download/success' - UseBasicParsing).Links.href
59- $fileUri = ($links | Select-String - Pattern ' .*Windows-x86_64.exe' | Get-Unique ).Tostring().Trim()
59+ $fileUri = ($links | Select-String - Pattern ' .*Anaconda3.* Windows-x86_64.exe' | Get-Unique ).Tostring().Trim()
6060Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' anaconda.exe' ) - Verbose
6161
62- if ($InstallPwsh7ForPipKernel ) {
63- Write-Verbose ' Downloading latest PowerShell 7...'
64- $releaseURI = ' https://github.com/PowerShell/PowerShell/releases'
65- $latestRelease = (Invoke-WebRequest - Uri " $releaseURI /latest" - UseBasicParsing - Headers @ {' Accept' = ' application/json' }| ConvertFrom-Json ).update_url
66- $versionString = $latestRelease -replace ' .*tag/(.*)' , ' $1'
67- $links = (Invoke-WebRequest - Uri " $releaseURI /expanded_assets/$ ( $versionString ) " - UseBasicParsing).Links.href
68- $fileUri = ' https://github.com' + ($links | Select-String - Pattern ' .*x64.msi' | Get-Unique ).Tostring().Trim()
69- Write-Verbose " Download from $fileUri "
70- Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' pwsh.msi' ) - Verbose
71- }
72-
7362if ($InstallDotnetInteractive ) {
74- Write-Verbose ' Downloading latest .NET Core SDK...'
63+ Write-Host ' Downloading latest .NET Core SDK...'
7564 $links = (Invoke-WebRequest - Uri ' https://dotnet.microsoft.com/download' - UseBasicParsing).Links.href
7665 $latestVer = (($links | Select-String - Pattern ' .*sdk.*windows-x64-installer' ) -replace ' .*sdk-(([0-9]+\.){1}[0-9]+(\.[0-9]+)?)-.*' , ' $1' | Measure-Object - Maximum).Maximum
7766 $latestUri = ' https://dotnet.microsoft.com' + ($links | Select-String - Pattern " .*sdk-$latestVer -windows-x64-installer" | Get-Unique ).Tostring().Trim()
7867 $fileUri = ((Invoke-WebRequest - Uri $latestUri - UseBasicParsing).Links.href | Select-String - Pattern ' .*\.exe' | Get-Unique ).Tostring().Trim()
7968 Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' dotnet.exe' ) - Verbose
8069}
8170elseif ($InstallPwsh7SDK ) {
82- Write-Verbose ' Downloading latest .NET Runtime...'
71+ Write-Host ' Downloading latest .NET Runtime...'
8372 $links = (Invoke-WebRequest - Uri ' https://dotnet.microsoft.com/en-us/download/dotnet/8.0/runtime' - UseBasicParsing).Links.href
8473 $latestVer = (($links | Select-String - Pattern ' .*runtime.*windows-x64-installer' ) -replace ' .*runtime-(([0-9]+\.){1}[0-9]+(\.[0-9]+)?)-.*' , ' $1' | Measure-Object - Maximum).Maximum
8574 $latestUri = ' https://dotnet.microsoft.com' + ($links | Select-String - Pattern " .*runtime-$latestVer -windows-x64-installer" | Get-Unique ).Tostring().Trim()
8675 $fileUri = ((Invoke-WebRequest - Uri $latestUri - UseBasicParsing).Links.href | Select-String - Pattern ' .*\.exe' | Get-Unique ).Tostring().Trim()
8776 Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' dotnet.exe' ) - Verbose
8877}
8978
90- if (-not ($UsePipKernel )) {
91- $releaseURI = ' https://github.com/sakaztk/Jupyter-PowerShellSDK/releases'
92- $latestRelease = (Invoke-WebRequest - Uri " $releaseURI /latest" - UseBasicParsing - Headers @ {' Accept' = ' application/json' }| ConvertFrom-Json ).update_url
93- $versionString = $latestRelease -replace ' .*tag/(.*)' , ' $1'
94- $links = (Invoke-WebRequest - Uri " $releaseURI /expanded_assets/$ ( $versionString ) " - UseBasicParsing).Links.href
95- Write-Verbose ' Downloading latest DeepAQ pwsh5 Kernel...'
96- $fileUri = ' https://github.com' + ( $links | Select-String - Pattern ' .*PowerShell5.zip' | Get-Unique ).Tostring().Trim()
97- Invoke-WebRequest - uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Verbose
98- Write-Verbose ' Downloading latest DeepAQ pwshSDK Kernel...'
99- $fileUri = ' https://github.com' + ( $links | Select-String - Pattern ' Jupyter-PowerShellSDK-7.*\.zip' | Get-Unique ).Tostring().Trim()
100- Invoke-WebRequest - uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - Verbose
101- }
79+ $releaseURI = ' https://github.com/sakaztk/Jupyter-PowerShellSDK/releases'
80+ $latestRelease = (Invoke-WebRequest - Uri " $releaseURI /latest" - UseBasicParsing - Headers @ {' Accept' = ' application/json' }| ConvertFrom-Json ).update_url
81+ $versionString = $latestRelease -replace ' .*tag/(.*)' , ' $1'
82+ $links = (Invoke-WebRequest - Uri " $releaseURI /expanded_assets/$ ( $versionString ) " - UseBasicParsing).Links.href
83+ Write-Host ' Downloading latest DeepAQ pwsh5 Kernel...'
84+ $fileUri = ' https://github.com' + ( $links | Select-String - Pattern ' .*PowerShell5.zip' | Get-Unique ).Tostring().Trim()
85+ Invoke-WebRequest - uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Verbose
86+ Write-Host ' Downloading latest DeepAQ pwshSDK Kernel...'
87+ $fileUri = ' https://github.com' + ( $links | Select-String - Pattern ' Jupyter-PowerShellSDK-7.*\.zip' | Get-Unique ).Tostring().Trim()
88+ Invoke-WebRequest - uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - Verbose
10289
10390if ($null -ne $exProgressPreference ) {
10491 Write-Verbose " Restore $ProgressPreference to $exProgressPreference "
10592 $ProgressPreference = $exProgressPreference
10693}
10794
108- Write-Output ' Installing Anaconda. this may take survival minutes...'
95+ Write-Host ' Installing Anaconda. this may take survival minutes...'
10996$process = Start-Process - FilePath ' anaconda.exe' - ArgumentList $condaOpt - PassThru
11097for ($i = 0 ; $i -le 100 ; $i = ($i + 1 ) % 100 ) {
11198 Write-Progress - Activity ' Installer' - PercentComplete $i - Status ' Installing...'
@@ -119,68 +106,44 @@ if ($CleanupDownloadFiles) {
119106 Start-Sleep - Seconds 5
120107 Remove-Item ' anaconda.exe' - Force
121108}
122- Write-Output ' ...Done'
109+ Write-Host ' ...Done'
123110& " $dataPath \Anaconda3\shell\condabin\conda-hook.ps1"
124111conda activate
125- Write-Verbose ' ##### Jupyter Installation #####'
112+ Write-Host ' ##### Jupyter Installation #####'
126113conda upgrade - y pip
127114conda upgrade - y wheel
128115conda install - y jupyter
129116conda install - y notebook
130117conda install - y jupyterlab
131118conda install - y - c conda- forge nodejs
132119
133- if ($InstallNBExtensions ) {
134- conda install - y - c conda- forge jupyter_nbextensions_configurator
135- jupyter nbextensions_configurator enable
136- pip install https:// github.com / ipython- contrib/ jupyter_contrib_nbextensions/ tarball/ master
137- jupyter contrib nbextension install $pyTypeOpt
138- }
139- if ($UsePipKernel ) {
140- pip install powershell_kernel
141- python - m powershell_kernel.install $pyTypeOpt
142- if ($InstallPwsh7ForPipKernel ) {
143- Write-Verbose ' Installing PowerShell 7...'
144- Start-Process - FilePath ' pwsh.msi' - ArgumentList ' /passive' - Wait
145- Copy-Item - Path " $kernelPath \powershell" - Destination " $kernelPath \powershell7" - Recurse - Force
146- $fileContent = Get-Content " $kernelPath \powershell7\kernel.json" - Raw
147- $fileContent = $filecontent -replace ' "display_name": "[^"]*"' , ' "display_name": "PowerShell 7"'
148- $fileContent = $filecontent -replace ' "powershell_command": "[^"]*"' , " `" powershell_command`" : `" pwsh.exe`" "
149- $filecontent | Set-Content " $kernelPath \powershell7\kernel.json"
150- if ($CleanupDownloadFiles ) {
151- Start-Sleep - Seconds 5
152- Remove-Item ' pwsh.msi' - Force
153- }
154- }
155- }
156- else {
157- Write-Verbose ' Installing DeepAQ pwsh5 Kernel...'
158- $installPath = Join-Path $packagePath ' powershell5_kernel'
159- Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShell5.zip' ) - DestinationPath $installPath - Force
160- New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershell5\' ) - Force
161- Invoke-WebRequest - UseBasicParsing - Verbose - Uri ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_64.png' - OutFile (Join-Path $kernelPath ' \powershell5\logo-64x64.png' )
162- Add-Type - AssemblyName System.Drawing
163- $image = [System.Drawing.Image ]::FromFile((Join-Path $kernelPath ' \powershell5\logo-64x64.png' ))
164- $bitmap32 = New-Object System.Drawing.Bitmap(32 , 32 )
165- [System.Drawing.Graphics ]::FromImage($bitmap32 ).DrawImage($image , 0 , 0 , 32 , 32 )
166- $bitmap32.Save ((Join-Path $kernelPath ' \powershell5\logo-32x32.png' ), [System.Drawing.Imaging.ImageFormat ]::Png)
120+ Write-Host ' Installing DeepAQ pwsh5 Kernel...'
121+ $installPath = Join-Path $packagePath ' powershell5_kernel'
122+ Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShell5.zip' ) - DestinationPath $installPath - Force
123+ New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershell5\' ) - Force
124+ Invoke-WebRequest - UseBasicParsing - Verbose - Uri ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_64.png' - OutFile (Join-Path $kernelPath ' \powershell5\logo-64x64.png' )
125+ Add-Type - AssemblyName System.Drawing
126+ $image = [System.Drawing.Image ]::FromFile((Join-Path $kernelPath ' \powershell5\logo-64x64.png' ))
127+ $bitmap32 = New-Object System.Drawing.Bitmap(32 , 32 )
128+ [System.Drawing.Graphics ]::FromImage($bitmap32 ).DrawImage($image , 0 , 0 , 32 , 32 )
129+ $bitmap32.Save ((Join-Path $kernelPath ' \powershell5\logo-32x32.png' ), [System.Drawing.Imaging.ImageFormat ]::Png)
167130@"
168131{
169- "argv": [
170- "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShell5.exe",
171- "{connection_file}"
172- ],
173- "display_name": "PowerShell 5",
174- "language": "Powershell"
132+ "argv": [
133+ "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShell5.exe",
134+ "{connection_file}"
135+ ],
136+ "display_name": "PowerShell 5",
137+ "language": "Powershell"
175138}
176139"@ | Set-Content - Path (Join-Path $kernelPath ' \powershell5\kernel.json' )
177- Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershell5\' ) - Force
178- if ($CleanupDownloadFiles ) {
179- Remove-Item (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Force
180- }
140+ Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershell5\' ) - Force
141+ if ($CleanupDownloadFiles ) {
142+ Remove-Item (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Force
181143}
144+
182145if ($InstallPwsh7SDK ) {
183- Write-Verbose ' Installing DeepAQ pwshSDK Kernel...'
146+ Write-Host ' Installing DeepAQ pwshSDK Kernel...'
184147 $installPath = Join-Path $packagePath ' powershellSDK_kernel'
185148 Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - DestinationPath $installPath - Force
186149 New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershellSDK\' ) - Force
@@ -192,12 +155,12 @@ if ($InstallPwsh7SDK) {
192155 $bitmap32.Save ((Join-Path $kernelPath ' \powershellSDK\logo-32x32.png' ), [System.Drawing.Imaging.ImageFormat ]::Png)
193156@"
194157{
195- "argv": [
196- "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShellSDK.exe",
197- "{connection_file}"
198- ],
199- "display_name": "PowerShell 7 (SDK)",
200- "language": "Powershell"
158+ "argv": [
159+ "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShellSDK.exe",
160+ "{connection_file}"
161+ ],
162+ "display_name": "PowerShell 7 (SDK)",
163+ "language": "Powershell"
201164}
202165"@ | Set-Content - Path (Join-Path $kernelPath ' \powershellSDK\kernel.json' )
203166 Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershellSDK\' ) - Force
@@ -207,9 +170,9 @@ if ($InstallPwsh7SDK) {
207170}
208171
209172if ($InstallDotnetInteractive ) {
210- Write-Verbose ' Installing .NET SDK...'
173+ Write-Host ' Installing .NET SDK...'
211174 Start-Process - FilePath ' dotnet.exe' - ArgumentList ' /install /passive /norestart' - Wait
212- Write-Verbose ' Installing .NET Interactive...'
175+ Write-Host ' Installing .NET Interactive...'
213176 $env: Path = [System.Environment ]::GetEnvironmentVariable(" Path" , " Machine" ) + " ;" + [System.Environment ]::GetEnvironmentVariable(" Path" , " User" )
214177 dotnet tool install - g -- add-source " https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" Microsoft.dotnet- interactive
215178 dotnet interactive jupyter install -- path " $kernelPath "
@@ -219,7 +182,7 @@ if ($InstallDotnetInteractive) {
219182 }
220183}
221184elseif ($InstallPwsh7SDK ) {
222- Write-Verbose ' Installing .NET Runtime...'
185+ Write-Host ' Installing .NET Runtime...'
223186 Start-Process - FilePath (Join-Path $WorkingFolder ' dotnet.exe' ) - ArgumentList ' /install /passive /norestart' - Wait
224187 if ($CleanupDownloadFiles ) {
225188 Start-Sleep - Seconds 5
0 commit comments