Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires -RunAsAdministrator
- # Useful if deploying script with Intune; exits on first detection
- $EXIT_WITH_ERROR = $true
- # Intune seems to ignore the exit code, only responds to Write-Error
- $EXIT_WITH_ERROR_CODE = 1
- # Look for version 3.0.0 through 3.0.6; includes build numbers (fake examples: 3.0.0.5 and 3.1.0 r3)
- $VERSION_3XX_REGEX = "3\.0\.[0-6](?:\.[0-9])*"
- $COMMON_DIRECTORIES = @(
- "C:\Program Files",
- "C:\Program Files (x86)",
- "C:\ProgramData"
- )
- $USER_DIRECTORIES = (Get-ChildItem -Path "C:\Users" -Directory).FullName
- # No reliable way of determing which directory a package is installed
- Get-Package -Name *openssl* -ErrorAction SilentlyContinue | ForEach-Object {
- # Version might be empty, so the name may contain it
- if ($_.Name -match $VERSION_3XX_REGEX -or $_.Version -match $VERSION_3XX_REGEX) {
- if ($_.Metadata["Publisher"]) {
- $msg = "Installed program: $($_.Name) - $($_.Metadata["Publisher"])"
- }
- else {
- $msg = "Installed program: $($_.Name)"
- }
- if ($EXIT_WITH_ERROR) {
- Write-Error -Message $msg
- exit $EXIT_WITH_ERROR_CODE
- }
- else {
- Write-Warning -Message $msg
- }
- }
- }
- if ($env:PATH + $env:OPENSSL) {
- ($env:PATH + $env:OPENSSL).Split(";") | ForEach-Object {
- if ($_.ToLower().Contains("openssl")) {
- Get-ChildItem -Path $_ -Recurse -Filter "openssl.exe" | ForEach-Object {
- # Unsure if all version properties are populated; guessing FileVersionRaw is always present
- # Could compare the Version object instead of using RegEx
- if ((Get-Item -Path $_.FullName).VersionInfo.FileVersionRaw.ToString() -match $VERSION_3XX_REGEX) {
- if ($EXIT_WITH_ERROR) {
- Write-Error -Message "Environment variable: $($_.FullName)"
- exit $EXIT_WITH_ERROR_CODE
- }
- else {
- Write-Warning -Message "Environment variable: $($_.FullName)"
- }
- }
- }
- }
- }
- }
- # Some directories even a local admin can't access; errors will be suppressed
- $COMMON_DIRECTORIES | ForEach-Object {
- Get-ChildItem -Path $_ -Recurse -Filter "openssl.exe" -ErrorAction SilentlyContinue | ForEach-Object {
- if ((Get-Item -Path $_.FullName -ErrorAction SilentlyContinue).VersionInfo.FileVersionRaw.ToString() -match $VERSION_3XX_REGEX) {
- if ($EXIT_WITH_ERROR) {
- Write-Error -Message "Common folder: $($_.FullName)"
- exit $EXIT_WITH_ERROR_CODE
- }
- else {
- Write-Warning -Message "Common folder: $($_.FullName)"
- }
- }
- }
- }
- $USER_DIRECTORIES | ForEach-Object {
- Get-ChildItem -Path $_ -Recurse -Filter "openssl.exe" -ErrorAction SilentlyContinue | ForEach-Object {
- if ((Get-Item -Path $_.FullName -ErrorAction SilentlyContinue).VersionInfo.FileVersionRaw.ToString() -match $VERSION_3XX_REGEX) {
- if ($EXIT_WITH_ERROR) {
- Write-Error -Message "User profile: $($_.FullName)"
- exit $EXIT_WITH_ERROR_CODE
- }
- else {
- Write-Warning -Message "User profile: $($_.FullName)"
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement