Posted On December 4, 2019

PowerShell: Get Executable Version and File Location

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Get Executable Version and File Location
# Quick method to obtain computernames of all nodes in a cluster and adjoin result with standalone machine names
$standaloneFileServers="komputer1","komputer2"
$sourceClusters="cluster1","cluster2"
$nodes=$sourceClusters|%{get-clusternode -cluster $_}
$computerNames=$nodes.Name+$standaloneFileServers

# function to obtain the version of a particular excecutable
function getExecutableVersion{
param(
[string]$computername,
[string]$executablename="robocopy.exe"
)
$localComputerName=$env:computername
$isLocal=if($computername -match "(localhost|127.0.0.1|$localComputerName)"){$true}else{$false}

function getExeInfo{
param($exeName)
$exeFile=$(try{get-command $exeName -ea SilentlyContinue}catch{}).Definition;
$exeInfo=$(try{get-item $exeFile -ea SilentlyContinue}catch{}).versionInfo;
$osName=(Get-WmiObject -class Win32_OperatingSystem).Caption;
$osArchitecture=$ENV:PROCESSOR_ARCHITECTURE
$exeInfo | Add-Member -MemberType NoteProperty -Name "osName" -Value $osName
$exeInfo | Add-Member -MemberType NoteProperty -Name "osArchitecture" -Value $osArchitecture
return $exeInfo;
}

if ($isLocal){
$exeInfo=getExeInfo -exeName $executablename;
}else{
$exeInfo=invoke-command -computername $computername -scriptblock{
param($importedFunc,$executablename)
[ScriptBlock]::Create($importedFunc).Invoke($executablename);
} -args ${function:getExeInfo},$executablename
}
if ($exeInfo){
$exeVersion=$exeInfo.ProductVersion;
$exeLocation=$exeInfo.FileName;
$fileVersion=$exeInfo.FileVersion;
$osName=$exeInfo.osName;
$osArchitecture=$exeInfo.osArchitecture;
return "$computername`: $osName $osArchitecture $executablename $exeVersion$(if($exeVersion -ne $fileVersion){" $fileVersion "})$exeLocation";
}else{
write-host "$executablename is not in the environmental paths of $computername";
}
}


$computerNames|getExecutableVersion -computerName $_ -executablename robocopy.exe

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Copying File Share Permissions from Source to Destination

# Copy-SMB-Share-Permissions.ps1 # Set some SMB Share variables $sourceSmbPath="\\FILESERVER002\Home" $destinationSmbPath="\\FILESERVER002-n\Home" $dateStamp = Get-Date -Format "yyyy-MM-dd-hhmmss"…

PowerShell: Get Active Directory Domain Controller Replication Status

$domaincontroller=(Get-ADForest |Select-Object -ExpandProperty RootDomain |Get-ADDomain |Select-Object -Property PDCEmulator).PDCEmulator; ## Define Objects ## $report = New-Object…

Basic HTML and HTML5: Use HTML5 to Require a Field

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…