function Import-Certificate
{
param
(
[IO.FileInfo] $CertFile = $(throw "Paramerter -CertFile [System.IO.FileInfo] is required."),
[string[]] $StoreNames = $(throw "Paramerter -StoreNames [System.String] is required."),
[switch] $LocalMachine,
[switch] $CurrentUser,
[string] $CertPassword,
[switch] $Verbose
)
begin
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Security")
}
process
{
if ($Verbose)
{
$VerbosePreference = 'Continue'
}
if (-not $LocalMachine -and -not $CurrentUser)
{
Write-Warning "One or both of the following parameters are required: '-LocalMachine' '-CurrentUser'. Skipping certificate '$CertFile'."
}
try
{
if ($_)
{
$certfile = $_
}
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certfile,$CertPassword
}
catch
{
Write-Error ("Error importing '$certfile': $_ .") -ErrorAction:Continue
}
if ($cert -and $LocalMachine)
{
$StoreScope = "LocalMachine"
$StoreNames | ForEach-Object {
$StoreName = $_
if (Test-Path "cert:\$StoreScope\$StoreName")
{
try
{
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store $StoreName, $StoreScope
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($cert)
$store.Close()
Write-Verbose "Successfully added '$certfile' to 'cert:\$StoreScope\$StoreName'."
}
catch
{
Write-Error ("Error adding '$certfile' to 'cert:\$StoreScope\$StoreName': $_ .") -ErrorAction:Continue
}
}
else
{
Write-Warning "Certificate store '$StoreName' does not exist. Skipping..."
}
}
}
if ($cert -and $CurrentUser)
{
$StoreScope = "CurrentUser"
$StoreNames | ForEach-Object {
$StoreName = $_
if (Test-Path "cert:\$StoreScope\$StoreName")
{
try
{
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store $StoreName, $StoreScope
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($cert)
$store.Close()
Write-Verbose "Successfully added '$certfile' to 'cert:\$StoreScope\$StoreName'."
}
catch
{
Write-Error ("Error adding '$certfile' to 'cert:\$StoreScope\$StoreName': $_ .") -ErrorAction:Continue
}
}
else
{
Write-Warning "Certificate store '$StoreName' does not exist. Skipping..."
}
}
}
}
end
{ }
}
$ScriptPad = $Script:MyInvocation.MyCommand.Path
$ScriptFolder = Split-Path -Parent $ScriptPad
Write-Host "Try to add certificates..."
$filename = Join-Path -Path $ScriptFolder -ChildPath "cert_fedict.cer"
$filename2 = Join-Path -Path $ScriptFolder -ChildPath "fedict_codesiging.cer"
try {
Import-Certificate -CertFile $filename -StoreNames TrustedPublisher -LocalMachine
Import-Certificate -CertFile $filename2 -StoreNames TrustedPublisher -LocalMachine
Write-Host "Certificates ready`n"
} catch {
Write-Error "Failed while adding certificate..."
}
write-host "Installing driver...`n"
. $ScriptFolder\Manage-Drivers.ps1 -DriverSource "$ScriptFolder\BeID Minidriver" -LogName "eID_driver.log"
write-host "Installing Belgium e-ID msi...`n"
Start-Process -FilePath "msiexec.exe" -ArgumentList "/norestart /i $ScriptFolder\BeidMW_64_4.1.18.msi /qn /l*vx c:\logs\beid4.1.18.log" -Wait
if (gwmi -Namespace root\cimv2\sms -class SMS_InstalledSoftware | ?{$_.SoftwareCode -like "{DB942AEA-93D6-4FE4-8862-180D35A71730}"}) {
Write-Host "Installation completed`n"
}
View inventory records anonymously contributed by opt-in users of the K1000 Systems Management Appliance.