diff --git a/README.md b/README.md index 27b0a36..74454f0 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Install-Module PSReleaseTools On PowerShell you might need to run: ```powershell -Install-Module PSReleaseTools [-scope currentuser] +Install-Module PSReleaseTools [-Scope CurrentUser] ``` ## Support diff --git a/Tests/PSReleaseTools.tests.ps1 b/Tests/PSReleaseTools.tests.ps1 index d24e10a..9794dac 100644 --- a/Tests/PSReleaseTools.tests.ps1 +++ b/Tests/PSReleaseTools.tests.ps1 @@ -3,94 +3,94 @@ Remove-Module PSReleaseTools -ErrorAction SilentlyContinue $here = Split-Path -Parent $MyInvocation.MyCommand.Path $modRoot = Split-Path -Parent $here | Convert-Path -Write-Host "Importing module from $script:modroot" -ForegroundColor magenta +Write-Host "Importing module from $script:modroot" -ForegroundColor Magenta Import-Module $modRoot -Force InModuleScope PSReleaseTools { - $modPath = Get-Module psreleasetools | Select-Object path | Split-Path + $modPath = Get-Module PSReleaseTools | Select-Object path | Split-Path Describe PSReleaseTools { It "Has exported commands" { - {Get-Command -Module PSReleaseTools} | Should Be $true + {Get-Command -Module PSReleaseTools} | Should -Be $true } It "Has a README.md file" { - $f = Get-Item -Path $(Join-path -path $modpath -childpath README.md) - $f.name | Should Be "readme.md" + $f = Get-Item -Path $(Join-Path -Path $modpath -ChildPath README.md) + $f.name | Should -Be "readme.md" } Context Manifest { It "Has a manifest" { - Get-Item -Path $modpath\PSReleaseTools.psd1 | Should Be $True + Get-Item -Path $modpath\PSReleaseTools.psd1 | Should -Be $true } It "Has a license URI" { - (Get-Module psreleasetools).PrivateData["PSData"]["LicenseUri"] | Should be $True + (Get-Module PSReleaseTools).PrivateData["PSData"]["LicenseUri"] | Should -Be $true } It "Has a project URI" { - (Get-Module psreleasetools).PrivateData["PSData"]["ProjectUri"] | Should be $True + (Get-Module PSReleaseTools).PrivateData["PSData"]["ProjectUri"] | Should -Be $true } } #context } Describe Get-PSReleaseAsset { It "Runs without error" { - {$script:data = Get-PSReleaseAsset -ErrorAction Stop} | Should Not Throw + {$script:data = Get-PSReleaseAsset -ErrorAction Stop} | Should -Not -Throw } It "Writes one or more objects to the pipeline" { - $script:data.count | Should beGreaterThan 1 + $script:data.count | Should -BeGreaterThan 1 } $FamilyValues = (Get-Command Get-PSReleaseAsset).Parameters["Family"].Attributes.ValidValues It "Has a validation set for Family" { - $FamilyValues.count | Should Be 12 + $FamilyValues.count | Should -Be 12 } It "Should fail with a bad Family value" { - {Get-PSReleaseAsset -Family FOO -ErrorAction} | Should Throw + {Get-PSReleaseAsset -Family FOO -ErrorAction} | Should -Throw } It "Should get release assets for Ubuntu" { $script:dl = Get-PSReleaseAsset -Family Ubuntu - ($script:dl).Count | Should beGreaterThan 0 + ($script:dl).Count | Should -BeGreaterThan 0 } It "Result should have a Filename property" { - ($script:dl)[0].Filename | Should Be $True + ($script:dl)[0].Filename | Should -Be $true } It "Result should have an URL property with https" { - ($Script:dl)[0].url | Should Match "^https" + ($Script:dl)[0].URL | Should -Match "^https" } It "Result should have an [int] SizeMB property" { - ($script:dl)[0].sizeMB | Should BeOfType "System.Int32" + ($script:dl)[0].SizeMB | Should -BeOfType "System.Int32" } } Describe Get-PSReleaseSummary { It "Runs without error" { - {$script:sum = Get-PSReleaseSummary -ErrorAction Stop} | Should Not Throw + {$script:sum = Get-PSReleaseSummary -ErrorAction Stop} | Should -Not -Throw } It "Writes a string to the pipeline" { - $script:sum.getType().Name | Should Be "string" + $script:sum.GetType().Name | Should -Be "string" } } Describe Save-PSReleaseAsset { It "Has no tests defined at this time." { - $true | should be $True + $true | Should -Be $true } } Describe Install-PSPreview { It "Has no tests defined at this time." { - $true | should be $True + $true | Should -Be $true } } Describe Install-PSCore { It "Has no tests defined at this time." { - $true | should be $True + $true | Should -Be $true } } } \ No newline at end of file diff --git a/functions/private.ps1 b/functions/private.ps1 index 5c8d97d..f4c3999 100644 --- a/functions/private.ps1 +++ b/functions/private.ps1 @@ -1,50 +1,50 @@ #these are internal functions for the PSReleaseTools module #define an internal function to download the file -Function DL { - [cmdletbinding(SupportsShouldProcess)] - Param([string]$Source, [string]$Destination, [string]$hash, [switch]$Passthru) +function DL { + [CmdletBinding(SupportsShouldProcess)] + param([string]$Source, [string]$Destination, [string]$Hash, [switch]$Passthru) - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] $Source to $Destination" + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] $Source to $Destination" - if ($pscmdlet.ShouldProcess($Destination, "Downloading $source")) { - Invoke-Webrequest -Uri $source -UseBasicParsing -DisableKeepAlive -OutFile $Destination - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Comparing file hash to $hash" + if ($PSCmdlet.ShouldProcess($Destination, "Downloading $Source")) { + Invoke-WebRequest -Uri $source -UseBasicParsing -DisableKeepAlive -OutFile $Destination + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Comparing file hash to $Hash" $f = Get-FileHash -Path $Destination -Algorithm SHA256 - if ($f.hash -ne $hash) { + if ($f.Hash -ne $Hash) { Write-Warning "Hash mismatch. $Destination may be incomplete." } - if ($passthru) { + if ($Passthru) { Get-Item $Destination } } #should process } #DL -Function GetData { - [cmdletbinding()] - Param( +function GetData { + [CmdletBinding()] + param( [switch]$Preview ) $uri = "https://api.github.com/repos/powershell/powershell/releases" - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Getting current release information from $uri" - $get = Invoke-Restmethod -uri $uri -Method Get -ErrorAction stop + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Getting current release information from $uri" + $get = Invoke-RestMethod -Uri $uri -Method Get -ErrorAction Stop if ($Preview) { - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Getting latest preview" - ($get).where( {$_.prerelease}) | Select-Object -first 1 + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Getting latest preview" + ($get).where( {$_.prerelease}) | Select-Object -First 1 } else { - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Getting latest stable release" - ($get).where( { -NOT $_.prerelease}) | Select-Object -first 1 + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Getting latest stable release" + ($get).where( { -NOT $_.prerelease}) | Select-Object -First 1 } } -Function InstallMsi { - [cmdletbinding(SupportsShouldProcess)] - Param( +function InstallMsi { + [CmdletBinding(SupportsShouldProcess)] + param( [Parameter(Mandatory, HelpMessage = "The full path to the MSI file")] [ValidateScript({Test-Path $_})] [string]$Path, @@ -57,7 +57,7 @@ Function InstallMsi { [switch]$EnableContextMenu ) - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Creating Start-Process parameters" + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Creating Start-Process parameters" $modeOption = switch ($Mode) { "Full" {"/qf" } @@ -74,14 +74,14 @@ Function InstallMsi { $installOption += " ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1" } - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] FilePath: $Path" - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] ArgumentList: $installOption" + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] FilePath: $Path" + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] ArgumentList: $installOption" - if ($pscmdlet.ShouldProcess("$Path $installOption")) { - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Starting installation process" + if ($PSCmdlet.ShouldProcess("$Path $installOption")) { + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Starting installation process" Start-Process -FilePath $Path -ArgumentList $installOption } - Write-Verbose "[$((Get-Date).TimeofDay) $($myinvocation.mycommand)] Ending function" + Write-Verbose "[$((Get-Date).TimeofDay) $($MyInvocation.MyCommand)] Ending function" } #close installmsi \ No newline at end of file diff --git a/functions/public.ps1 b/functions/public.ps1 index b86e8ee..6e43b7a 100644 --- a/functions/public.ps1 +++ b/functions/public.ps1 @@ -1,17 +1,17 @@ #These are public functions for the PSReleaseTools module -Function Get-PSReleaseCurrent { - [cmdletbinding()] +function Get-PSReleaseCurrent { + [CmdletBinding()] [OutputType("PSCustomObject")] - Param( + param( [Parameter(HelpMessage = "Get the latest preview release")] [switch]$Preview ) - Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.Mycommand)" + begin { + Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.MyCommand)" } #begin - Process { + process { $data = GetData @PSBoundParameters @@ -34,16 +34,16 @@ Function Get-PSReleaseCurrent { } } #process - End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.Mycommand)" + end { + Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.MyCommand)" } #end } -Function Get-PSReleaseSummary { - [cmdletbinding(DefaultParameterSetName = "default")] +function Get-PSReleaseSummary { + [CmdletBinding(DefaultParameterSetName = "default")] [OutputType([System.String[]])] - Param( + param( [Parameter(HelpMessage = "Display as a markdown document", ParameterSetName = "md")] [switch]$AsMarkdown, [Parameter(ParameterSetName = "md")] @@ -52,7 +52,7 @@ Function Get-PSReleaseSummary { [Parameter(HelpMessage = "Get the latest preview release")] [switch]$Preview ) - DynamicParam { + dynamicparam { if ($IsWindows -OR $PSEdition -eq 'Desktop') { #define a parameter attribute object @@ -77,12 +77,12 @@ Function Get-PSReleaseSummary { } #dynamic parameter - Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.Mycommand)" + begin { + Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.MyCommand)" } #begin - Process { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Using parameter set $($pscmdlet.ParameterSetName)" + process { + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Using parameter set $($PSCmdlet.ParameterSetName)" $PSBoundParameters | Out-String | Write-Verbose if ($Preview) { $data = GetData -Preview @@ -98,25 +98,25 @@ Function Get-PSReleaseSummary { else { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Displaying locally" $dl = $data.assets | - Select-Object @{Name = "Filename"; Expression = {$_.name}}, + Select-Object @{Name = "Filename"; Expression = {$_.Name}}, @{Name = "Updated"; Expression = {$_.updated_at -as [datetime]}}, @{Name = "SizeMB"; Expression = {$_.size / 1MB -as [int]}} if ($AsMarkdown) { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Formatting as markdown" #create a markdown table from download data - $tbl = (($DL | ConvertTo-Csv -notypeInformation -delimiter "|").Replace('"', '') -Replace '^', "|") -replace "$", "|`n" + $tbl = (($DL | ConvertTo-Csv -NoTypeInformation -Delimiter "|").Replace('"', '') -Replace '^', "|") -replace "$", "|`n" $out = @" -# $($data.Name.trim()) +# $($data.name.Trim()) -$($data.body.trim()) +$($data.body.Trim()) ## Downloads $($tbl[0])|---|---|---| -$($tbl[1..$($tbl.count)]) -Published: $($data.Published_At -as [datetime]) +$($tbl[1..$($tbl.Count)]) +Published: $($data.published_at -as [datetime]) "@ } @@ -126,8 +126,8 @@ Published: $($data.Published_At -as [datetime]) $out = @" ----------------------------------------------------------- -$($data.Name) -Published: $($data.Published_At -as [datetime]) +$($data.name) +Published: $($data.published_at -as [datetime]) ----------------------------------------------------------- $($data.body) @@ -144,25 +144,25 @@ $($DL | Out-String) } } #process - End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.Mycommand)" + end { + Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.MyCommand)" } #end } -Function Save-PSReleaseAsset { +function Save-PSReleaseAsset { - [cmdletbinding(DefaultParameterSetName = "All", SupportsShouldProcess)] + [CmdletBinding(DefaultParameterSetName = "All", SupportsShouldProcess)] [OutputType([System.IO.FileInfo])] - Param( + param( [Parameter(Position = 0, HelpMessage = "Where do you want to save the files?")] [ValidateScript( { if (Test-Path $_) { - $True + $true } else { - Throw "Cannot validate path $_" + throw "Cannot validate path $_" } })] [string]$Path = ".", @@ -189,41 +189,41 @@ Function Save-PSReleaseAsset { ) - Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.Mycommand)" + begin { + Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.MyCommand)" } #begin - Process { + process { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Using Parameter set $($PSCmdlet.ParameterSetName)" if ($PSCmdlet.ParameterSetName -match "All|Family") { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting latest releases from $uri" - Try { + try { $data = Get-PSReleaseAsset -Preview:$Preview -ErrorAction Stop } - Catch { + catch { Write-Warning $_.exception.message #bail out - Return + return } } - Switch ($PSCmdlet.ParameterSetName) { + switch ($PSCmdlet.ParameterSetName) { "All" { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Downloading all releases to $Path" foreach ($asset in $data) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ...$($Asset.filename) [$($asset.hash)]" + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ...$($asset.filename) [$($asset.Hash)]" $target = Join-Path -Path $path -ChildPath $asset.filename - DL -source $asset.url -Destination $Target -hash $asset.hash -passthru:$passthru + DL -source $asset.URL -Destination $Target -Hash $asset.Hash -passthru:$passthru } } #all "Family" { #download individual release files Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Downloading releases for $($family -join ',')" $assets = @() - Foreach ($item in $Family) { + foreach ($item in $Family) { - Switch ($item) { + switch ($item) { "Windows" { $assets += $data.where( {$_.filename -match 'win-x\d{2}'})} "Rhel" { $assets += $data.where( {$_.filename -match 'rhel'})} "Raspbian" { $assets += $data.where( {$_.filename -match 'linux-arm'})} @@ -236,7 +236,7 @@ Function Save-PSReleaseAsset { "AppImage" { $assets += $data.where( {$_.filename -match 'appimage'})} "FXDependent" { $assets += $data.where( {$_.filename -match 'fxdependent'})} "Alpine" {$assets += $data.where( {$_.filename -match 'alpine' })} - } #Switch + } #switch if ($PSBoundParameters.ContainsKey("Format")) { $type = $PSBoundParameters["format"] -join "|" @@ -245,38 +245,38 @@ Function Save-PSReleaseAsset { } foreach ($asset in $Assets) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ...$($Asset.filename) [$($asset.hash)]" + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ...$($Asset.filename) [$($asset.Hash)]" $target = Join-Path -Path $path -ChildPath $asset.fileName - DL -source $asset.url -Destination $Target -hash $asset.hash -passthru:$passthru + DL -source $asset.URL -Destination $Target -Hash $asset.Hash -passthru:$passthru } #foreach asset } #foreach family name } #Family "File" { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ...$($asset.filename) [$($asset.hash)]" + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] ...$($asset.filename) [$($asset.Hash)]" $target = Join-Path -Path $path -ChildPath $asset.fileName - DL -source $asset.url -Destination $Target -hash $asset.hash -passthru:$passthru + DL -source $asset.URL -Destination $Target -Hash $asset.Hash -passthru:$passthru } #file } #switch parameter set name } #process - End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.Mycommand)" + end { + Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.MyCommand)" } #end } -Function Get-PSReleaseAsset { +function Get-PSReleaseAsset { - [cmdletbinding()] + [CmdletBinding()] [OutputType("PSCustomObject")] - Param( + param( [Parameter(HelpMessage = "Limit results to a given platform. The default is all platforms.")] [ValidateSet("Rhel", "Raspbian", "Ubuntu", "Debian", "Windows", "AppImage", "Arm", "MacOS", "Alpine", "FXDependent", "CentOS", "Linux")] [string[]]$Family, [ValidateSet('deb', 'gz', 'msi', 'pkg', 'rpm', 'zip', 'msix')] [Parameter(HelpMessage = "Limit results to a given format. The default is all formats.")] [string[]]$Format, - [alias("x64")] + [Alias("x64")] [switch]$Only64Bit, [Parameter(HelpMessage = "Get the latest preview release.")] [switch]$Preview, @@ -284,19 +284,19 @@ Function Get-PSReleaseAsset { [switch]$LTS ) - Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.Mycommand)" + begin { + Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.MyCommand)" } #begin - Process { - Try { + process { + try { if ($Preview) { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting preview assets" - $data = GetData -Preview -ErrorAction stop + $data = GetData -Preview -ErrorAction Stop } else { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting normal assets" - $data = GetData -ErrorAction stop + $data = GetData -ErrorAction Stop } #parse out file names and hashes #updated pattern 10 March 2020 to capture LTS assets @@ -308,13 +308,13 @@ Function Get-PSReleaseAsset { $r = $rx.Matches($data.body) $r | ForEach-Object -Begin { $h = @{} - } -process { + } -Process { #if there is a duplicate entry, assume it is part of a Note - $f = $_.groups["file"].value.trim() - $v = $_.groups["hash"].value.trim() + $f = $_.Groups["file"].Value.Trim() + $v = $_.Groups["hash"].Value.Trim() if (-not ($h.ContainsKey($f))) { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding $f [$v]" - $h.add($f, $v ) + $h.Add($f, $v ) } else { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Ignoring duplicate asset: $f [$v]" @@ -326,7 +326,7 @@ Function Get-PSReleaseAsset { $assets = $data.assets | Select-Object @{Name = "FileName"; Expression = {$_.Name}}, @{Name = "Family"; Expression = { - Switch -regex ($_.name) { + switch -regex ($_.name) { "Win-x\d{2}" {"Windows" ; break} "arm\d{2}.zip" {"Arm" ; break} "Ubuntu" {"Ubuntu"; break} @@ -343,13 +343,13 @@ Function Get-PSReleaseAsset { } }, @{Name = "Format"; Expression = { - $_.name.split(".")[-1] + $_.name.Split(".")[-1] } }, @{Name = "SizeMB"; Expression = {$_.size / 1MB -as [int32]}}, - @{Name = "Hash"; Expression = {$h.item($_.name)}}, - @{Name = "Created"; Expression = {$_.Created_at -as [datetime]}}, - @{Name = "Updated"; Expression = {$_.Updated_at -as [datetime]}}, + @{Name = "Hash"; Expression = {$h.Item($_.name)}}, + @{Name = "Created"; Expression = {$_.created_at -as [datetime]}}, + @{Name = "Updated"; Expression = {$_.updated_at -as [datetime]}}, @{Name = "URL"; Expression = {$_.browser_download_Url}}, @{Name = "DownloadCount"; Expression = {$_.download_count}} @@ -376,16 +376,16 @@ Function Get-PSReleaseAsset { $assets } else { - Write-Warning "Get-PSReleaseAsset Failed to find any release assets using the specified critiria." + Write-Warning "Get-PSReleaseAsset Failed to find any release assets using the specified criteria." } } #Try catch { - Throw $_ + throw $_ } } #process - End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.Mycommand)" + end { + Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.MyCommand)" } #end } @@ -402,9 +402,9 @@ Display Options r - Reduced UI f - Full UI (default) #> -Function Install-PSPreview { - [cmdletbinding(SupportsShouldProcess)] - Param( +function Install-PSPreview { + [CmdletBinding(SupportsShouldProcess)] + param( [Parameter(HelpMessage = "Specify the path to the download folder")] [string]$Path = $env:TEMP, [Parameter(HelpMessage = "Specify what kind of installation you want. The default if a full interactive install.")] @@ -415,17 +415,17 @@ Function Install-PSPreview { [Parameter(HelpMessage = "Enable the PowerShell context menu in Windows Explorer.")] [switch]$EnableContextMenu ) - Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" + begin { + Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($MyInvocation.MyCommand)" } #begin - Process { + process { #only run on Windows - if (($psedition -eq 'Desktop') -OR ($PSVersionTable.platform -eq 'Win32NT')) { + if (($PSEdition -eq 'Desktop') -OR ($PSVersionTable.Platform -eq 'Win32NT')) { if ($PSBoundParameters.ContainsKey("WhatIf")) { #create a dummy file name is using -Whatif Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating a dummy file for WhatIf purposes" - $filename = Join-Path -path $Path -ChildPath "whatif-PS7Preview.msi" + $filename = Join-Path -Path $Path -ChildPath "whatif-PS7Preview.msi" } else { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Saving download to $Path" @@ -449,9 +449,9 @@ Function Install-PSPreview { Mode = $Mode EnableRemoting = $EnableRemoting EnableContextMenu = $EnableContextMenu - ErrorAction = "stop" + ErrorAction = "Stop" } - if ($pscmdlet.ShouldProcess($filename, "Install PowerShell Preview using $mode mode")) { + if ($PSCmdlet.ShouldProcess($filename, "Install PowerShell Preview using $mode mode")) { InstallMSI @inParams } } @@ -461,16 +461,16 @@ Function Install-PSPreview { } } #process - End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + end { + Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($MyInvocation.MyCommand)" } #end } #close Install-PSPreview -Function Install-PowerShell { - [cmdletbinding(SupportsShouldProcess)] - [alias("Install-PSCore")] - Param( +function Install-PowerShell { + [CmdletBinding(SupportsShouldProcess)] + [Alias("Install-PSCore")] + param( [Parameter(HelpMessage = "Specify the path to the download folder")] [string]$Path = $env:TEMP, [Parameter(HelpMessage = "Specify what kind of installation you want. The default if a full interactive install.")] @@ -481,17 +481,17 @@ Function Install-PowerShell { [Parameter(HelpMessage = "Enable the PowerShell context menu in Windows Explorer.")] [switch]$EnableContextMenu ) - Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" + begin { + Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($MyInvocation.MyCommand)" } #begin - Process { + process { #only run on Windows - if (($psedition -eq 'Desktop') -OR ($PSVersionTable.platform -eq 'Win32NT')) { + if (($PSEdition -eq 'Desktop') -OR ($PSVersionTable.Platform -eq 'Win32NT')) { if ($PSBoundParameters.ContainsKey("WhatIf")) { #create a dummy file name is using -Whatif Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating a dummy file for WhatIf purposes" - $filename = Join-Path -path $Path -ChildPath "whatif-ps7.msi" + $filename = Join-Path -Path $Path -ChildPath "whatif-ps7.msi" } else { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Saving download to $Path " @@ -513,9 +513,9 @@ Function Install-PowerShell { Mode = $Mode EnableRemoting = $EnableRemoting EnableContextMenu = $EnableContextMenu - ErrorAction = "stop" + ErrorAction = "Stop" } - if ($pscmdlet.ShouldProcess($filename, "Install PowerShell using $mode mode")) { + if ($PSCmdlet.ShouldProcess($filename, "Install PowerShell using $mode mode")) { InstallMSI @inParams } } @@ -525,8 +525,8 @@ Function Install-PowerShell { } } #process - End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + end { + Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($MyInvocation.MyCommand)" } #end } #close Install-PSCore \ No newline at end of file