有没有办法通过带有智能卡的 powershell 远程激活 windows?

Is there a way to activate windows remotely via powershell with smart card?

出于某种原因,我们的域没有 KMS 服务器设置。所以我们被迫手动激活windows。这仅适用于 180 天,但用户开始看到有关 windows 的弹出窗口将在此之前几周到期。

ICM -CN $CN {slmgr /fta <thumbprint> <pin>}    

我正在尝试找到一种方法来远程推送这个将激活的衬垫 windows 但是我收到错误 0x8010000C,这基本上只是抱怨智能卡没有插入遥控器计算机。

所以除了获得所用证书的数字副本并将其安装在每台计算机上之外,我几乎没有其他想法,希望它从中提取而不是从我的卡中提取。

最终不得不写的比我想写的多,不得不放弃远程 运行 的尝试。因此创建了一个本地脚本,并想与 运行 遇到相同问题的任何人分享这个,尽管这可能而且应该是罕见的。

可能有更好的方法来编写它,但它目前正在运行。

function msgbox {
param (
    [string]$Message = 'Windows will expire soon. Would you like to renew the license key?',
    [string]$Title = 'Windows Activation Script',   
    [string]$buttons = 'YesNo'
)
# This function displays a message box by calling the .Net Windows.Forms (MessageBox class)

# Load the assembly
Add-Type -AssemblyName System.Windows.Forms | Out-Null

# Define the button types
switch ($buttons) {
   'ok' {$btn = [System.Windows.Forms.MessageBoxButtons]::OK; break}
   'okcancel' {$btn = [System.Windows.Forms.MessageBoxButtons]::OKCancel; break}
   'AbortRetryIgnore' {$btn = [System.Windows.Forms.MessageBoxButtons]::AbortRetryIgnore; break}
   'YesNoCancel' {$btn = [System.Windows.Forms.MessageBoxButtons]::YesNoCancel; break}
   'YesNo' {$btn = [System.Windows.Forms.MessageBoxButtons]::yesno; break}
   'RetryCancel'{$btn = [System.Windows.Forms.MessageBoxButtons]::RetryCancel; break}
   default {$btn = [System.Windows.Forms.MessageBoxButtons]::RetryCancel; break}
}
  # Display the message box
  $script:Return=[System.Windows.Forms.MessageBox]::Show($Message,$Title,$btn)
}

function msgbox2 {
param (
    [string]$Message = "Windows has expired. The script will now attempt to activate Windows.`n`nPlease click ok to continue.",
    [string]$Title = 'Windows Activation Script',   
    [string]$buttons = 'ok'
)
Add-Type -AssemblyName System.Windows.Forms | Out-Null
switch ($buttons) {
   'ok' {$btn = [System.Windows.Forms.MessageBoxButtons]::OK; break}
}
  $script:Return=[System.Windows.Forms.MessageBox]::Show($Message,$Title,$btn)
}

# Grabs Users Email Certificate Thumbprint
function Grab_Thumbprint
{($EmailCert = (Get-ChildItem -path Cert:\CurrentUser\My | Where-Object { $_.FriendlyName -match 'Signature' } | Where-Object { $_.Subject -match ($env:UserName).Substring(0,4) } | Select-Object Thumbprint | ForEach-Object { $_.Thumbprint }))}

# Checks Experation Date of Licence
function Check_date
{($line = (slmgr /xpr | Out-String ))
($line2 = [regex]::Matches($line, '(\d+/\d+/\d\d\d\d)') | Select-Object Value | ForEach-Object { $_.Value })
if($line2 -match '(\d+/\d+/\d\d\d\d)'){
$line2 = Get-Date $line2 -f MM/dd/yyyy
$line2 = (Get-Date $line2).AddMonths(-1)
$script:Expired = (get-date $line2) -lt (get-date)} else {
($line3 = [regex]::Matches($line, 'Windows is in Notification mode') | Select-Object Value | ForEach-Object { $_.Value })
if($line3 -eq 'Windows is in Notification mode'){$script:Expired2 = $true} else {}}}

# Attempts to Activate Windows
function Activate
{Write-Host "This will take 10 seconds to access your CAC" -ForegroundColor Cyan
($test = (slmgr /fta $emailcert | Out-String))
$test2 = [regex]::Matches($test, 'Error: ..........') | Select-Object Value | ForEach-Object { $_.Value }
$test2 = $test2 + ' - Please notify your ITS of any errors listed here.'
$test3 = [regex]::Matches($test, 'Product activated successfully') | Select-Object Value | ForEach-Object { $_.Value }
[System.Windows.Forms.MessageBox]::Show("$test2`n$test3",'Windows Activation Status')}

# Clears any old data

$dateTime    = $null
$line        = $null
$line2       = $null
$line3       = $null
$EmailCert   = $null
$Expired     = $null
$Expired2    = $null
$test        = $null
$test2       = $null
$test3       = $null

# Do Stuff

$EmailCert = Grab_Thumbprint

Check_date

If($Expired -eq $true)    { (msgbox) }
If($Expired2 -eq $true)    { (msgbox2) }
If(($Expired -eq $true -or $Expired2 -eq $true) -and ($Return -eq 'Yes' -or $Return -eq 'OK'))     { (Activate) } else { Write-Host "Exiting" }