Задача сделать импорт pfx сертификата в личное хранилище \LocalMachine\My
Сделал gpo task scheduled
Program
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Argument:
-ExecutionPolicy Bypass -File "\\путь\Install-Certificate.ps1"
Сам Install-Certificate.ps1
# Computer name $computerName = $env:COMPUTERNAME # Start transcript logging Write-Output "# Start transcript logging" Start-Transcript -Path "\\путь\transcript_$computerName.txt" -Force # Path to the certificate file $certPath = "\\путь\Certificate_Deployment\pc.pfx" #$password = "пароль" #[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($password)) # Encoded password in Base64 $encodedPassword = "пароль" # This is "пароль" encoded in Base64 # Decode the password from Base64 and convert it to a secure string $passwordBytes = [System.Convert]::FromBase64String($encodedPassword) $passwordPlainText = [System.Text.Encoding]::UTF8.GetString($passwordBytes) $password = $passwordPlainText | ConvertTo-SecureString -AsPlainText -Force # Task name in Task Scheduler $taskName = "zcdqLcOWMA6X" # Замените на имя вашей задачи # Check if the certificate exists in the store Write-Output "# Check if the certificate exists in the store" $existingCert = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object { $_.Subject -like "*srv.vpnpc*" } if ($existingCert) { Write-Output "The certificate already exists in the store." } else { # Import the certificate Write-Output "# Importing the certificate..." Import-PfxCertificate -FilePath $certPath -CertStoreLocation Cert:\LocalMachine\My -Password $password Write-Output "The certificate has been imported successfully." } # Remove the scheduled task after successful execution or if the certificate already exists try { Write-Output "# Removing the scheduled task..." Unregister-ScheduledTask -TaskName $taskName -Confirm:$false Write-Output "Scheduled task '$taskName' has been removed successfully." } catch { Write-Warning "Failed to remove the scheduled task. Error: $_" } # Stop transcript logging Stop-Transcript
Проверяет есть установленный сертификат если есть скрипт не выполняется. После завершения task удаляет задание из task scheduled
Similar Posts:
- Как импортировать сертификат для компьютера в личное (personal\my) хранилище сертификатов с помощью sccm.
- Как поменять сертификаты на iis для всех сайтов с помощью powershell.
- Как обновить сертификат ssl hp ilo через PowerShell и Windows CA
- Как настроить шифрование компьютеров на базе win 10 – 11 в Active Directory с помощью BitLocker , gpo и PowerShell c сохранением ключей
- Как экспортировать и импортировать все запланированные задания (task sheduler) из Windows 2008 r2