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')
15+ $OutputEncoding = [System.Text.Encoding ]::GetEncoding(' utf-8' )
1516$psBoundParameters.Keys | ForEach-Object {
1617 if ($ ($PSBoundParameters .$_.GetType ().Name) -eq ' SwitchParameter' ) {
1718 $paramStrings += " -$_ "
@@ -32,15 +33,15 @@ switch ($installationType) {
3233 $dataPath = " $env: ProgramData "
3334 $kernelPath = Join-Path $env: ProgramData ' \Miniconda3\share\jupyter\kernels'
3435 $packagePath = Join-Path $env: ProgramData ' \Miniconda3\Lib\site-packages'
35- $pyTypeOpt = ' --sys-prefix'
36+ # $pyTypeOpt = '--sys-prefix'
3637 [System.Environment ]::SetEnvironmentVariable(' PYTHONUTF8' , 1 , [System.EnvironmentVariableTarget ]::Machine)
3738 }
3839 { @ (' user' , ' justme' ) -contains $_ } {
3940 $condaOpt = ' /InstallationType=JustMe /AddToPath=0 /RegisterPython=1 /NoRegistru=0 /Noscripts=o /S'
4041 $dataPath = $env: UserProfile
4142 $kernelPath = Join-Path $env: AppData ' \jupyter\kernels'
4243 $packagePath = Join-Path $env: USERPROFILE ' \Miniconda3\Lib\site-packages'
43- $pyTypeOpt = ' --user'
44+ # $pyTypeOpt = '--user'
4445 [System.Environment ]::SetEnvironmentVariable(' PYTHONUTF8' , 1 , [System.EnvironmentVariableTarget ]::User)
4546 }
4647 default {
@@ -54,50 +55,37 @@ if ($ProgressPreference -ne 'SilentlyContinue') {
5455 $ProgressPreference = ' SilentlyContinue'
5556}
5657
57- Write-Verbose ' Downloading latest Miniconda...'
58+ Write-Host ' Downloading latest Miniconda...'
5859$fileUri = ' https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe'
59- Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' miniconda.exe' ) - Verbose
60-
61- if ($InstallPwsh7ForPipKernel ) {
62- Write-Verbose ' Downloading latest PowerShell 7...'
63- $releaseURI = ' https://github.com/PowerShell/PowerShell/releases'
64- $latestRelease = (Invoke-WebRequest - Uri " $releaseURI /latest" - UseBasicParsing - Headers @ {' Accept' = ' application/json' }| ConvertFrom-Json ).update_url
65- $versionString = $latestRelease -replace ' .*tag/(.*)' , ' $1'
66- $links = (Invoke-WebRequest - Uri " $releaseURI /expanded_assets/$ ( $versionString ) " - UseBasicParsing).Links.href
67- $fileUri = ' https://github.com' + ($links | Select-String - Pattern ' .*x64.msi' | Get-Unique ).Tostring().Trim()
68- Write-Verbose " Download from $fileUri "
69- Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' pwsh.msi' ) - Verbose
70- }
60+ Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' miniconda.exe' ) - Verbose:$VerbosePreference
7161
7262if ($InstallDotnetInteractive ) {
73- Write-Verbose ' Downloading latest .NET SDK...'
63+ Write-Host ' Downloading latest .NET SDK...'
7464 $links = (Invoke-WebRequest - Uri ' https://dotnet.microsoft.com/download' - UseBasicParsing).Links.href
7565 $latestVer = (($links | Select-String - Pattern ' .*sdk.*windows-x64-installer' ) -replace ' .*sdk-(([0-9]+\.){1}[0-9]+(\.[0-9]+)?)-.*' , ' $1' | Measure-Object - Maximum).Maximum
7666 $latestUri = ' https://dotnet.microsoft.com' + ($links | Select-String - Pattern " .*sdk-$latestVer -windows-x64-installer" | Get-Unique ).Tostring().Trim()
7767 $fileUri = ((Invoke-WebRequest - Uri $latestUri - UseBasicParsing).Links.href | Select-String - Pattern ' .*\.exe' | Get-Unique ).Tostring().Trim()
78- Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' dotnet.exe' ) - Verbose
68+ Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' dotnet.exe' ) - Verbose: $VerbosePreference
7969}
8070else {
81- Write-Verbose ' Downloading latest .NET Runtime...'
71+ Write-Host ' Downloading latest .NET Runtime...'
8272 $links = (Invoke-WebRequest - Uri ' https://dotnet.microsoft.com/en-us/download/dotnet/8.0/runtime' - UseBasicParsing).Links.href
8373 $latestVer = (($links | Select-String - Pattern ' .*runtime.*windows-x64-installer' ) -replace ' .*runtime-(([0-9]+\.){1}[0-9]+(\.[0-9]+)?)-.*' , ' $1' | Measure-Object - Maximum).Maximum
8474 $latestUri = ' https://dotnet.microsoft.com' + ($links | Select-String - Pattern " .*runtime-$latestVer -windows-x64-installer" | Get-Unique ).Tostring().Trim()
8575 $fileUri = ((Invoke-WebRequest - Uri $latestUri - UseBasicParsing).Links.href | Select-String - Pattern ' .*\.exe' | Get-Unique ).Tostring().Trim()
86- Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' dotnet.exe' ) - Verbose
76+ Invoke-WebRequest - Uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' dotnet.exe' ) - Verbose: $VerbosePreference
8777}
8878
89- if (-not ($UsePipKernel )) {
90- $releaseURI = ' https://github.com/sakaztk/Jupyter-PowerShellSDK/releases'
91- $latestRelease = (Invoke-WebRequest - Uri " $releaseURI /latest" - UseBasicParsing - Headers @ {' Accept' = ' application/json' }| ConvertFrom-Json ).update_url
92- $versionString = $latestRelease -replace ' .*tag/(.*)' , ' $1'
93- $links = (Invoke-WebRequest - Uri " $releaseURI /expanded_assets/$ ( $versionString ) " - UseBasicParsing).Links.href
94- Write-Verbose ' Downloading latest DeepAQ pwsh5 Kernel...'
95- $fileUri = ' https://github.com' + ( $links | Select-String - Pattern ' .*PowerShell5.zip' | Get-Unique ).Tostring().Trim()
96- Invoke-WebRequest - uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Verbose
97- Write-Verbose ' Downloading latest DeepAQ pwshSDK Kernel...'
98- $fileUri = ' https://github.com' + ( $links | Select-String - Pattern ' Jupyter-PowerShellSDK-7.*\.zip' | Get-Unique ).Tostring().Trim()
99- Invoke-WebRequest - uri $fileUri - UseBasicParsing - OutFile (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - Verbose
100- }
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:$VerbosePreference
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:$VerbosePreference
10189
10290if ($null -ne $exProgressPreference ) {
10391 Write-Verbose " Restore $ProgressPreference to $exProgressPreference "
@@ -128,79 +116,55 @@ conda install -y notebook
128116conda install - y jupyterlab
129117conda install - y - c conda- forge nodejs
130118
131- if ($InstallNBExtensions ) {
132- conda install - y - c conda- forge jupyter_nbextensions_configurator
133- jupyter nbextensions_configurator enable
134- pip install https:// github.com / ipython- contrib/ jupyter_contrib_nbextensions/ tarball/ master
135- jupyter contrib nbextension install $pyTypeOpt
136- }
137- if ($UsePipKernel ) {
138- pip install powershell_kernel
139- python - m powershell_kernel.install $pyTypeOpt
140- if ($InstallPwsh7ForPipKernel ) {
141- Write-Verbose ' Installing PowerShell 7...'
142- Start-Process - FilePath ' pwsh.msi' - ArgumentList ' /passive' - Wait
143- Copy-Item - Path " $kernelPath \powershell" - Destination " $kernelPath \powershell7" - Recurse - Force
144- $fileContent = Get-Content " $kernelPath \powershell7\kernel.json" - Raw
145- $fileContent = $filecontent -replace ' "display_name": "[^"]*"' , ' "display_name": "PowerShell 7"'
146- $fileContent = $filecontent -replace ' "powershell_command": "[^"]*"' , " `" powershell_command`" : `" pwsh.exe`" "
147- $filecontent | Set-Content " $kernelPath \powershell7\kernel.json"
148- if ($CleanupDownloadFiles ) {
149- Start-Sleep - Seconds 5
150- Remove-Item ' pwsh.msi' - Force
151- }
152- }
153- }
154- else {
155- Write-Verbose ' Installing DeepAQ pwsh5 Kernel...'
156- $installPath = Join-Path $packagePath ' powershell5_kernel'
157- Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShell5.zip' ) - DestinationPath $installPath - Force
158- New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershell5\' ) - Force
159- Invoke-WebRequest - UseBasicParsing - Verbose - Uri ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_64.png' - OutFile (Join-Path $kernelPath ' \powershell5\logo-64x64.png' )
160- Add-Type - AssemblyName System.Drawing
161- $image = [System.Drawing.Image ]::FromFile((Join-Path $kernelPath ' \powershell5\logo-64x64.png' ))
162- $bitmap32 = New-Object System.Drawing.Bitmap(32 , 32 )
163- [System.Drawing.Graphics ]::FromImage($bitmap32 ).DrawImage($image , 0 , 0 , 32 , 32 )
164- $bitmap32.Save ((Join-Path $kernelPath ' \powershell5\logo-32x32.png' ), [System.Drawing.Imaging.ImageFormat ]::Png)
119+ Write-Verbose ' Installing DeepAQ pwsh5 Kernel...'
120+ $installPath = Join-Path $packagePath ' powershell5_kernel'
121+ Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShell5.zip' ) - DestinationPath $installPath - Force
122+ New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershell5\' ) - Force
123+ Invoke-WebRequest - UseBasicParsing - Verbose - Uri ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_64.png' - OutFile (Join-Path $kernelPath ' \powershell5\logo-64x64.png' )
124+ Add-Type - AssemblyName System.Drawing
125+ $image = [System.Drawing.Image ]::FromFile((Join-Path $kernelPath ' \powershell5\logo-64x64.png' ))
126+ $bitmap32 = New-Object System.Drawing.Bitmap(32 , 32 )
127+ [System.Drawing.Graphics ]::FromImage($bitmap32 ).DrawImage($image , 0 , 0 , 32 , 32 )
128+ $bitmap32.Save ((Join-Path $kernelPath ' \powershell5\logo-32x32.png' ), [System.Drawing.Imaging.ImageFormat ]::Png)
165129@"
166130{
167- "argv": [
168- "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShell5.exe",
169- "{connection_file}"
170- ],
171- "display_name": "PowerShell 5",
172- "language": "Powershell"
131+ "argv": [
132+ "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShell5.exe",
133+ "{connection_file}"
134+ ],
135+ "display_name": "PowerShell 5",
136+ "language": "Powershell"
173137}
174138"@ | Set-Content - Path (Join-Path $kernelPath ' \powershell5\kernel.json' )
175- Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershell5\' ) - Force
176- if ($CleanupDownloadFiles ) {
177- Remove-Item (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Force
178- }
139+ Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershell5\' ) - Force - Verbose:$VerbosePreference
140+ if ($CleanupDownloadFiles ) {
141+ Remove-Item (Join-Path $WorkingFolder ' PowerShell5.zip' ) - Force - Verbose:$VerbosePreference
179142}
143+
180144if ($InstallPwsh7SDK ) {
181145 Write-Verbose ' Installing DeepAQ pwshSDK Kernel...'
182146 $installPath = Join-Path $packagePath ' powershellSDK_kernel'
183- Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - DestinationPath $installPath - Force
184- New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershellSDK\' ) - Force
185- Invoke-WebRequest - UseBasicParsing - Verbose - Uri ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_black_64.png' - OutFile (Join-Path $kernelPath ' \powershellSDK\logo-64x64.png' )
147+ Expand-Archive - Path (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - DestinationPath $installPath - Force - Verbose: $VerbosePreference
148+ New-Item - ItemType Directory - Path (Join-Path $kernelPath ' \powershellSDK\' ) - Force - Verbose: $VerbosePreference
149+ Invoke-WebRequest - UseBasicParsing - Uri ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/assets/Powershell_black_64.png' - OutFile (Join-Path $kernelPath ' \powershellSDK\logo-64x64.png' ) - Verbose: $VerbosePreference
186150 Add-Type - AssemblyName System.Drawing
187151 $image = [System.Drawing.Image ]::FromFile((Join-Path $kernelPath ' \powershellSDK\logo-64x64.png' ))
188152 $bitmap32 = New-Object System.Drawing.Bitmap(32 , 32 )
189153 [System.Drawing.Graphics ]::FromImage($bitmap32 ).DrawImage($image , 0 , 0 , 32 , 32 )
190154 $bitmap32.Save ((Join-Path $kernelPath ' \powershellSDK\logo-32x32.png' ), [System.Drawing.Imaging.ImageFormat ]::Png)
191155@"
192156{
193- "argv": [
194- "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShellSDK.exe",
195- "{connection_file}"
196- ],
197- "display_name": "PowerShell 7 (SDK)",
198- "language": "Powershell"
157+ "argv": [
158+ "$ ( $installPath.replace (' \' , ' /' )) /Jupyter_PowerShellSDK.exe",
159+ "{connection_file}"
160+ ],
161+ "display_name": "PowerShell 7 (SDK)",
162+ "language": "Powershell"
199163}
200164"@ | Set-Content - Path (Join-Path $kernelPath ' \powershellSDK\kernel.json' )
201- Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershellSDK\' ) - Force
165+ Move-Item - Path (Join-Path $installPath ' *.png' ) - Destination (Join-Path $kernelPath ' \powershellSDK\' ) - Force - Verbose: $VerbosePreference
202166 if ($CleanupDownloadFiles ) {
203- Remove-Item (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - Force
167+ Remove-Item (Join-Path $WorkingFolder ' PowerShellSDK.zip' ) - Force - Verbose: $VerbosePreference
204168 }
205169}
206170
@@ -213,15 +177,15 @@ if ($InstallDotnetInteractive) {
213177 dotnet interactive jupyter install -- path " $kernelPath "
214178 if ($CleanupDownloadFiles ) {
215179 Start-Sleep - Seconds 5
216- Remove-Item ' dotnet.exe' - Force
180+ Remove-Item ' dotnet.exe' - Force - Verbose: $VerbosePreference
217181 }
218182}
219183elseif ($InstallPwsh7SDK ) {
220184 Write-Verbose ' Installing .NET Runtime...'
221185 Start-Process - FilePath (Join-Path $WorkingFolder ' dotnet.exe' ) - ArgumentList ' /install /passive /norestart' - Wait
222186 if ($CleanupDownloadFiles ) {
223187 Start-Sleep - Seconds 5
224- Remove-Item (Join-Path $WorkingFolder ' dotnet.exe' ) - Force
188+ Remove-Item (Join-Path $WorkingFolder ' dotnet.exe' ) - Force - Verbose: $VerbosePreference
225189 }
226190}
227191
0 commit comments