Find the Path for Excel-addin in Powershell
$Excel.Addins
returns objects with more properties than just the Name, but that Name property is the addins Filename and includes the extension, like .XLL
or .XLAM
.
Another property you could probe is the .Title
.
Try
try {
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $false
# you may also try Where-Object { $_.Title -match 'MyAddinName' }
$myAddIn = $Excel.Addins | Where-Object { $_.Name -match 'MyAddinName' }
if ($myAddIn) {
Write-Host "AddIn '$($myAddIn.Name)' found in '$($myAddIn.Path)'"
# copy the supporting file to the Addin's path
Copy-Item -Path 'X:\YourSupportingFile' -Destination $myAddIn.Path
}
else {
Write-Warning "Addin 'MyAddinName' not found"
}
}
catch {
Write-Warning "Error:`r`n$($_.Exception.Message)"
}
finally {
if ($Excel) {
# close and cleanup COM object
$Excel.Quit()
$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
}
}
This assumes there is only one addin found with that name..
Instead of the regex -match
operator you could also use -like '*MyAddinName*'
which uses wildcars