Skip to content

Commit

Permalink
Improving Install-VcRedist
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Jun 26, 2018
1 parent 99a4a40 commit 02d46e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion VcRedist/Private/Get-InstalledSoftware.ps1
Expand Up @@ -44,7 +44,8 @@ Function Get-InstalledSoftware {
$selectProperties = @(
@{n = 'Name'; e = {$_.GetValue('DisplayName')}},
@{n = 'Version'; e = {$_.GetValue('DisplayVersion')}},
@{n = 'ProductCode'; e = {$_.PSChildName}}
@{n = 'ProductCode'; e = {$_.PSChildName}},
@{n = 'UninstallString'; e = {$_.GetValue('UninstallString')}}
)
Get-ChildItem @gciParams | Where-Object $WhereBlock | Select-Object -Property $selectProperties
}
Expand Down
8 changes: 6 additions & 2 deletions VcRedist/Public/Get-InstalledVcRedist.ps1
Expand Up @@ -31,8 +31,8 @@ Function Get-InstalledVcRedist {
Description:
Returns the installed Microsoft Visual C++ Redistributables from the current system including the Additional and Minimum Runtimes.
#>
[CmdletBinding(SupportsShouldProcess = $False)]
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
Param (
[Parameter(Mandatory = $False)]
[switch] $ExportAll
Expand All @@ -46,7 +46,11 @@ Function Get-InstalledVcRedist {
$VcRedists = $VcRedists | ForEach-Object { If (-not (Select-String -InputObject $_ -Pattern "Additional|Minimum")) {$_} } | `
Sort-Object Name
}


# Add Architecture property to each entry
$VcRedists | ForEach-Object { If ( $_.Name -contains "x64" ) `
{ $_ | Add-Member -NotePropertyName "Architecture" -NotePropertyValue "x64" } }

# Write the installed VcRedists to the pipeline
Write-Output $VcRedists
}
2 changes: 1 addition & 1 deletion VcRedist/Public/Get-VcList.ps1
Expand Up @@ -37,8 +37,8 @@ Function Get-VcList {
Description:
Return an array of the Visual C++ Redistributables listed in VisualCRedistributablesSupported.xml.
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[OutputType([Array])]
Param (
[Parameter(Mandatory = $False, Position = 0, HelpMessage = "Path to the XML document describing the Redistributables.")]
[ValidateNotNull()]
Expand Down
8 changes: 6 additions & 2 deletions VcRedist/Public/Install-VcRedist.ps1
Expand Up @@ -65,7 +65,8 @@ Function Install-VcRedist {
[bool]$Elevated = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
If ( !($Elevated) ) { Throw "Installing the Visual C++ Redistributables requires elevation."}

$UninstallPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
# $UninstallPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$Installed = Get-InstalledVcRedist
}
Process {
# Filter release and architecture if specified
Expand All @@ -80,7 +81,10 @@ Function Install-VcRedist {

# Loop through each Redistributable and install
ForEach ( $Vc in $VcList ) {
If (Get-ChildItem -Path $UninstallPath | Where-Object { $_.Name -like "*$($Vc.ProductCode)" }) {
# If (Get-ChildItem -Path $UninstallPath | Where-Object { $_.Name -like "*$($Vc.ProductCode)" }) {
# Write-Verbose "Skip: [$($Vc.Release)][$($Vc.Architecture)][$($Vc.Name)]"
#}
If ($Installed | Where-Object { $Vc.ProductCode -contains $_.ProductCode }) {
Write-Verbose "Skip: [$($Vc.Release)][$($Vc.Architecture)][$($Vc.Name)]"
}
Else {
Expand Down

0 comments on commit 02d46e6

Please sign in to comment.