Created
November 1, 2020 13:32
-
-
Save ducke/012652246c586ec0b004bcbaaabe20e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# The current state of the script logic\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\r\n", | |
"<div>\r\n", | |
" <div id='dotnet-interactive-this-cell-10384.597feb4e8fe448aea808227c08c157c1' style='display: none'>\r\n", | |
" The below script needs to be able to find the current output cell; this is an easy method to get it.\r\n", | |
" </div>\r\n", | |
" <script type='text/javascript'>\r\n", | |
"// ensure `require` is available globally\r\n", | |
"if (typeof require !== typeof Function || typeof require.config !== typeof Function) {\r\n", | |
" let require_script = document.createElement('script');\r\n", | |
" require_script.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js');\r\n", | |
" require_script.setAttribute('type', 'text/javascript');\r\n", | |
" require_script.onload = function () {\r\n", | |
" loadDotnetInteractiveApi();\r\n", | |
" };\r\n", | |
"\r\n", | |
" document.getElementsByTagName('head')[0].appendChild(require_script);\r\n", | |
"}\r\n", | |
"else {\r\n", | |
" loadDotnetInteractiveApi();\r\n", | |
"}\r\n", | |
"\r\n", | |
"async function probeAddresses(probingAddresses) {\r\n", | |
" function timeout(ms, promise) {\r\n", | |
" return new Promise(function (resolve, reject) {\r\n", | |
" setTimeout(function () {\r\n", | |
" reject(new Error('timeout'))\r\n", | |
" }, ms)\r\n", | |
" promise.then(resolve, reject)\r\n", | |
" })\r\n", | |
" }\r\n", | |
"\r\n", | |
" if (Array.isArray(probingAddresses)) {\r\n", | |
" for (let i = 0; i < probingAddresses.length; i++) {\r\n", | |
"\r\n", | |
" let rootUrl = probingAddresses[i];\r\n", | |
"\r\n", | |
" if (!rootUrl.endsWith('/')) {\r\n", | |
" rootUrl = `${rootUrl}/`;\r\n", | |
" }\r\n", | |
"\r\n", | |
" try {\r\n", | |
" let response = await timeout(1000, fetch(`${rootUrl}discovery`, {\r\n", | |
" method: 'POST',\r\n", | |
" cache: 'no-cache',\r\n", | |
" mode: 'cors',\r\n", | |
" timeout: 1000,\r\n", | |
" headers: {\r\n", | |
" 'Content-Type': 'text/plain'\r\n", | |
" },\r\n", | |
" body: probingAddresses[i]\r\n", | |
" }));\r\n", | |
"\r\n", | |
" if (response.status == 200) {\r\n", | |
" return rootUrl;\r\n", | |
" }\r\n", | |
" }\r\n", | |
" catch (e) { }\r\n", | |
" }\r\n", | |
" }\r\n", | |
"}\r\n", | |
"\r\n", | |
"function loadDotnetInteractiveApi() {\r\n", | |
" probeAddresses([\"http://192.168.70.1:1000/\", \"http://192.168.178.55:1000/\", \"http://172.31.176.1:1000/\", \"http://172.19.48.1:1000/\", \"http://127.0.0.1:1000/\"])\r\n", | |
" .then((root) => {\r\n", | |
" // use probing to find host url and api resources\r\n", | |
" // load interactive helpers and language services\r\n", | |
" let dotnetInteractiveRequire = require.config({\r\n", | |
" context: '10384.597feb4e8fe448aea808227c08c157c1',\r\n", | |
" paths: {\r\n", | |
" 'dotnet-interactive': `${root}resources`\r\n", | |
" }\r\n", | |
" }) || require;\r\n", | |
"\r\n", | |
" let dotnetInteractiveExtensionsRequire = require.config({\r\n", | |
" context: '10384.597feb4e8fe448aea808227c08c157c1',\r\n", | |
" paths: {\r\n", | |
" 'dotnet-interactive-extensions': `${root}extensions`\r\n", | |
" }\r\n", | |
" }) || require;\r\n", | |
"\r\n", | |
" if (!window.dotnetInteractiveRequire) {\r\n", | |
" window.dotnetInteractiveRequire = dotnetInteractiveRequire;\r\n", | |
" }\r\n", | |
"\r\n", | |
" if (!window.dotnetInteractiveExtensionsRequire) {\r\n", | |
" window.dotnetInteractiveExtensionsRequire = dotnetInteractiveExtensionsRequire;\r\n", | |
" }\r\n", | |
"\r\n", | |
" window.getExtensionRequire = function(extensionName, extensionCacheBuster) {\r\n", | |
" let paths = {};\r\n", | |
" paths[extensionName] = `${root}extensions/${extensionName}/resources/`;\r\n", | |
" \r\n", | |
" let internalRequire = require.config({\r\n", | |
" context: extensionCacheBuster,\r\n", | |
" paths: paths,\r\n", | |
" urlArgs: `cacheBuster=${extensionCacheBuster}`\r\n", | |
" }) || require;\r\n", | |
"\r\n", | |
" return internalRequire\r\n", | |
" };\r\n", | |
" \r\n", | |
" dotnetInteractiveRequire([\r\n", | |
" 'dotnet-interactive/dotnet-interactive'\r\n", | |
" ],\r\n", | |
" function (dotnet) {\r\n", | |
" dotnet.init(window);\r\n", | |
" },\r\n", | |
" function (error) {\r\n", | |
" console.log(error);\r\n", | |
" }\r\n", | |
" );\r\n", | |
" })\r\n", | |
" .catch(error => {console.log(error);});\r\n", | |
" }\r\n", | |
" </script>\r\n", | |
"</div>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"function Execute-Msi {\n", | |
" param (\n", | |
" [string]$exeMsiexec,\n", | |
" [string[]]$Parameters,\n", | |
" [switch]$PassThru = $false,\n", | |
" [switch]$SecureParameters = $false,\n", | |
" [boolean]$ExitOnProcessFailure = $true,\n", | |
" [boolean]$ContinueOnError = $false,\n", | |
" [switch]$NoWait = $false\n", | |
" )\n", | |
" [hashtable]$ExecuteProcessSplat = @{ Path = $exeMsiexec\n", | |
" Parameters = $argsMSI\n", | |
" WindowStyle = 'Normal' \n", | |
" }\n", | |
" If ($ContinueOnError) { $ExecuteProcessSplat.Add( 'ContinueOnError', $ContinueOnError) }\n", | |
" If ($SecureParameters) { $ExecuteProcessSplat.Add( 'SecureParameters', $SecureParameters) }\n", | |
" If ($PassThru) { $ExecuteProcessSplat.Add( 'PassThru', $PassThru) }\n", | |
" If ($ExitOnProcessFailure) { $ExecuteProcessSplat.Add( 'ExitOnProcessFailure', $ExitOnProcessFailure) }\n", | |
" If ($NoWait) { $ExecuteProcessSplat.Add( 'NoWait', $NoWait) }\n", | |
" # Call the Execute-Process function\n", | |
" <#\n", | |
" $CmdletBoundParameters = $PSBoundParameters | Format-Table -Property @{ Label = 'Parameter'; Expression = { \"[-$($_.Key)]\" } }, @{ Label = 'Value'; Expression = { $_.Value }; Alignment = 'Left' } -AutoSize -Wrap | Out-String\n", | |
" If ($CmdletBoundParameters) {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked with bound parameter(s): `n$CmdletBoundParameters\"\n", | |
" }\n", | |
" Else {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked without any bound parameters.\"\n", | |
" }\n", | |
" #>\n", | |
" $ExeBoundParam = $ExecuteProcessSplat | Format-Table -Property @{ Label = 'Parameter'; Expression = { \"[-$($_.Key)]\" } }, @{ Label = 'Value'; Expression = { $_.Value }; Alignment = 'Left' } -AutoSize -Wrap | Out-String\n", | |
" Write-Output \"Execute-Process invoked with parameters: `n$ExeBoundParam\"\n", | |
" If ($PassThru) {\n", | |
" [psobject]$ExecuteResults = Execute-Process @ExecuteProcessSplat\n", | |
" }\n", | |
" Else {\n", | |
" Execute-Process @ExecuteProcessSplat\n", | |
" }\n", | |
"}\n", | |
"function Execute-Process {\n", | |
" param (\n", | |
" [string]$Path,\n", | |
" [string[]]$Parameters,\n", | |
" [Diagnostics.ProcessWindowStyle]$WindowStyle = 'Normal',\n", | |
" [switch]$PassThru = $false,\n", | |
" [switch]$SecureParameters = $false,\n", | |
" [boolean]$ExitOnProcessFailure = $true,\n", | |
" [boolean]$ContinueOnError = $false,\n", | |
" [switch]$NoWait = $false\n", | |
" )\n", | |
" $CmdletBoundParameters = $PSBoundParameters | Format-Table -Property @{ Label = 'Parameter'; Expression = { \"[-$($_.Key)]\" } }, @{ Label = 'Value'; Expression = { $_.Value }; Alignment = 'Left' } -AutoSize -Wrap | Out-String\n", | |
" If ($CmdletBoundParameters) {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked with bound parameter(s): `n$CmdletBoundParameters\"\n", | |
" }\n", | |
" Else {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked without any bound parameters.\"\n", | |
" }\n", | |
" \"Called from={8}`r`nPath={0} Parameters={1} WindowStyle={2} PassThru={3} SecureParameters={4} ExitOnProcessFailure={5} ContinueOnError={6} NoWait={7}\" -f $Path,$Parameters,$WindowStyle,$PassThru,$SecureParameters,$ExitOnProcessFailure,$ContinueOnError,$NoWait,$((Get-PSCallStack)[1].Command)\n", | |
"}\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Execute-Process invoked with parameters: \n", | |
"\n", | |
"Parameter Value\n", | |
"--------- -----\n", | |
"[-Parameters] \n", | |
"[-Path] Foobar.msi\n", | |
"[-WindowStyle] Normal\n", | |
"\n", | |
"\n", | |
"Function Execute-Process invoked with bound parameter(s): \n", | |
"\n", | |
"Parameter Value\n", | |
"--------- -----\n", | |
"[-Parameters] \n", | |
"[-Path] Foobar.msi\n", | |
"[-WindowStyle] Normal\n", | |
"\n", | |
"\n", | |
"Execute-Msi\n", | |
"Path=Foobar.msi Parameters= WindowStyle=Normal PassThru=False SecureParameters=False ExitOnProcessFailure=True ContinueOnError=False NoWait=False\n" | |
] | |
} | |
], | |
"source": [ | |
"Execute-Msi -exeMsiexec \"Foobar.msi\" -ExitOnProcessFailure $false" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Add only boolean parameter to the splatting object" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"function Invoke-Msi {\n", | |
" param (\n", | |
" [string]$exeMsiexec,\n", | |
" [string[]]$Parameters,\n", | |
" [switch]$PassThru = $false,\n", | |
" [switch]$SecureParameters = $false,\n", | |
" [boolean]$ExitOnProcessFailure = $true,\n", | |
" [boolean]$ContinueOnError = $false,\n", | |
" [switch]$NoWait = $false\n", | |
" )\n", | |
" [hashtable]$ExecuteProcessSplat = @{ \n", | |
" Path = $exeMsiexec\n", | |
" Parameters = $argsMSI\n", | |
" WindowStyle = 'Normal'\n", | |
" ContinueOnError = $ContinueOnError\n", | |
" ExitOnProcessFailure = $ExitOnProcessFailure\n", | |
"\n", | |
" }\n", | |
" If ($SecureParameters) { $ExecuteProcessSplat.Add( 'SecureParameters', $SecureParameters) }\n", | |
" If ($PassThru) { $ExecuteProcessSplat.Add( 'PassThru', $PassThru) }\n", | |
" If ($NoWait) { $ExecuteProcessSplat.Add( 'NoWait', $NoWait) }\n", | |
" # Call the Execute-Process function\n", | |
" <#\n", | |
" $CmdletBoundParameters = $PSBoundParameters | Format-Table -Property @{ Label = 'Parameter'; Expression = { \"[-$($_.Key)]\" } }, @{ Label = 'Value'; Expression = { $_.Value }; Alignment = 'Left' } -AutoSize -Wrap | Out-String\n", | |
" If ($CmdletBoundParameters) {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked with bound parameter(s): `n$CmdletBoundParameters\"\n", | |
" }\n", | |
" Else {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked without any bound parameters.\"\n", | |
" }\n", | |
" #>\n", | |
" $ExeBoundParam = $ExecuteProcessSplat | Format-Table -Property @{ Label = 'Parameter'; Expression = { \"[-$($_.Key)]\" } }, @{ Label = 'Value'; Expression = { $_.Value }; Alignment = 'Left' } -AutoSize -Wrap | Out-String\n", | |
" Write-Output \"Execute-Process invoked with parameters: `n$ExeBoundParam\"\n", | |
" If ($PassThru) {\n", | |
" [psobject]$ExecuteResults = Execute-Process @ExecuteProcessSplat\n", | |
" }\n", | |
" Else {\n", | |
" Execute-Process @ExecuteProcessSplat\n", | |
" }\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Execute-Process invoked with parameters: \n", | |
"\n", | |
"Parameter Value\n", | |
"--------- -----\n", | |
"[-Parameters] \n", | |
"[-Path] Foobar.msi\n", | |
"[-ContinueOnError] False\n", | |
"[-ExitOnProcessFailure] False\n", | |
"[-WindowStyle] Normal\n", | |
"\n", | |
"\n", | |
"Function Execute-Process invoked with bound parameter(s): \n", | |
"\n", | |
"Parameter Value\n", | |
"--------- -----\n", | |
"[-Parameters] \n", | |
"[-Path] Foobar.msi\n", | |
"[-ContinueOnError] False\n", | |
"[-ExitOnProcessFailure] False\n", | |
"[-WindowStyle] Normal\n", | |
"\n", | |
"\n", | |
"Invoke-Msi\n", | |
"Path=Foobar.msi Parameters= WindowStyle=Normal PassThru=False SecureParameters=False ExitOnProcessFailure=False ContinueOnError=False NoWait=False\n" | |
] | |
} | |
], | |
"source": [ | |
"Invoke-Msi -exeMsiexec \"Foobar.msi\" -ExitOnProcessFailure $false" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Add boolean and switch parameter to the splatting object" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"function Invoke-SplatMsiExec {\n", | |
" param (\n", | |
" [string]$exeMsiexec,\n", | |
" [string[]]$Parameters,\n", | |
" [switch]$PassThru = $false,\n", | |
" [switch]$SecureParameters = $false,\n", | |
" [boolean]$ExitOnProcessFailure = $true,\n", | |
" [boolean]$ContinueOnError = $false,\n", | |
" [switch]$NoWait = $false\n", | |
" )\n", | |
" [hashtable]$ExecuteProcessSplat = @{ \n", | |
" Path = $exeMsiexec\n", | |
" Parameters = $argsMSI\n", | |
" WindowStyle = 'Normal'\n", | |
" PassThru = $PassThru\n", | |
" SecureParameters = $SecureParameters\n", | |
" ExitOnProcessFailure = $ExitOnProcessFailure\n", | |
" ContinueOnError = $ContinueOnError\n", | |
" NoWait = $NoWait\n", | |
" }\n", | |
"\n", | |
" # Call the Execute-Process function\n", | |
" <#\n", | |
" $CmdletBoundParameters = $PSBoundParameters | Format-Table -Property @{ Label = 'Parameter'; Expression = { \"[-$($_.Key)]\" } }, @{ Label = 'Value'; Expression = { $_.Value }; Alignment = 'Left' } -AutoSize -Wrap | Out-String\n", | |
" If ($CmdletBoundParameters) {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked with bound parameter(s): `n$CmdletBoundParameters\"\n", | |
" }\n", | |
" Else {\n", | |
" Write-Output \"Function $($MyInvocation.MyCommand) invoked without any bound parameters.\"\n", | |
" }\n", | |
" #>\n", | |
" If ($PassThru) {\n", | |
" [psobject]$ExecuteResults = Execute-Process @ExecuteProcessSplat\n", | |
" }\n", | |
" Else {\n", | |
" Execute-Process @ExecuteProcessSplat\n", | |
" }\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Function Execute-Process invoked with bound parameter(s): \n", | |
"\n", | |
"Parameter Value\n", | |
"--------- -----\n", | |
"[-SecureParameters] False\n", | |
"[-ExitOnProcessFailure] False\n", | |
"[-WindowStyle] Normal\n", | |
"[-NoWait] False\n", | |
"[-PassThru] False\n", | |
"[-ContinueOnError] False\n", | |
"[-Path] Foobar.msi\n", | |
"[-Parameters] \n", | |
"\n", | |
"\n", | |
"Invoke-SplatMsiExec\n", | |
"Path=Foobar.msi Parameters= WindowStyle=Normal PassThru=False SecureParameters=False ExitOnProcessFailure=False ContinueOnError=False NoWait=False\n" | |
] | |
} | |
], | |
"source": [ | |
"Invoke-SplatMsiExec -exeMsiexec \"Foobar.msi\" -ExitOnProcessFailure $false" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": ".NET (PowerShell)", | |
"language": "PowerShell", | |
"name": ".net-powershell" | |
}, | |
"language_info": { | |
"file_extension": ".ps1", | |
"mimetype": "text/x-powershell", | |
"name": "PowerShell", | |
"pygments_lexer": "powershell", | |
"version": "7.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment