Skip to content

Commit

Permalink
Add Java rehoming; fix cert filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianL-STCU committed Dec 14, 2018
1 parent f6250cc commit 253f560
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
12 changes: 7 additions & 5 deletions Find-Certificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
The value to search for, usually a string.
For a FindType of FindByTimeValid, FindByTimeNotYetValid, or FindByTimeExpired, the FindValue must be a datetime.
For a FindType of FindByApplicationPolicy or FindByCertificatePolicy, the FindValue can be a string or a
System.Security.Cryptography.Oid.
For a FindType of FindByApplicationPolicy or FindByCertificatePolicy, the FindValue can be a string or a
System.Security.Cryptography.Oid.
For a FindType of FindByKeyUsage, the FindValue can be a string or an int bitmask.
.Parameter FindType
The field of the certificate to compare to FindValue.
e.g. FindBySubjectName, FindByKeyUsage, FindByIssuerDistinguishedName
For a FindType of FindByTimeValid, FindByTimeNotYetValid, or FindByTimeExpired, the FindValue should be a datetime.
For a FindType of FindByApplicationPolicy or FindByCertificatePolicy, the FindValue can be a string or a
System.Security.Cryptography.Oid.
For a FindType of FindByApplicationPolicy or FindByCertificatePolicy, the FindValue can be a string or a
System.Security.Cryptography.Oid.
For a FindType of FindByKeyUsage, the FindValue can be a string or an int bitmask.
Omitting a FindType or StoreName will search all stores and common fields.
Expand Down Expand Up @@ -72,9 +72,11 @@ $cert =
if(!($StoreName -and $FindType))
{
Write-Verbose "Find '$FindValue'"
$now = Get-Date
ls Cert:\CurrentUser,Cert:\LocalMachine |
% {ls "Cert:\$($_.Location)\$($_.Name)"} |
? {$_.Subject,$_.Issuer,$_.Thumbprint |? {$_ -like "*$FindValue*"}}
? {$_.Subject,$_.Issuer,$_.Thumbprint |? {$_ -like "*$FindValue*"}} |
? {!$Valid -or ($now -ge $_.NotBefore -and $now -le $_.NotAfter)}
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Use-Java.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<#
.Synopsis
Switch the Java version for the current process by modifying environment variables.
.Parameter Path
The path to the JRE/JDK to use, which must contain bin\java.exe.
.Inputs
System.String path to use as the new JAVA_HOME environment variable.
.Example
Use-Java.ps1 "$env:ProgramFiles\OpenJDK\jdk-11.0.1"
#>

[CmdletBinding()] Param(
[Parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName)]
[ValidateScript({(Test-Path $_ -PathType Container) -and (Test-Path "$_\bin\java.exe" -PathType Leaf)})]
[Alias('FullName')][string]$Path
)

$env:JAVA_HOME = $Path
Write-Verbose "JAVA_HOME=$env:JAVA_HOME"
if($env:JDK_HOME)
{
$env:JDK_HOME = $env:JAVA_HOME
Write-Verbose "JDK_HOME=$env:JDK_HOME"
}
if($env:JRE_HOME -and (Test-Path "$env:JAVA_HOME\jre" -PathType Container))
{
$env:JRE_HOME = "$env:JAVA_HOME\jre"
Write-Verbose "JRE_HOME=$env:JRE_HOME"
}
if($env:CLASSPATH)
{
$env:CLASSPATH = ".;$env:JAVA_HOME\lib;$env:JAVA_HOME\jre\lib"
Write-Verbose "CLASSPATH=$env:CLASSPATH"
}
$env:Path = ($env:Path -split ';' |% {if($_ -match 'Java|JDK'){"$Path\bin"}else{$_}}) -join ';'
Write-Verbose "Path=$($env:Path -replace ';',([Environment]::NewLine))"
${java.exe} = (Get-Command java.exe -CommandType Application).Path
Write-Verbose "Using Java ${java.exe} ($((Get-Item ${java.exe}).VersionInfo.ProductVersion))"

0 comments on commit 253f560

Please sign in to comment.