由于某些原因,我们的域没有KMS服务器设置。因此,我们被迫手动激活Windows。这只能使用180天,但是用户会在几周之前开始看到有关Windows的弹出窗口即将失效。
ICM -CN $CN {slmgr /fta <thumbprint> <pin>}
我正在尝试找到一种方法来远程推动该衬垫以激活窗口,但是我收到错误0x8010000C,基本上是在抱怨智能卡未插入远程计算机。
因此,除了获得使用的证书的数字副本,然后将其安装在每台计算机上(希望它从我的卡而不是我的卡中提取)之外,我没有其他想法。
答案 0 :(得分:0)
最终不得不写比我想要的更多的东西,不得不放弃尝试远程运行它。因此创建了一个本地脚本,并希望与遇到相同问题的任何人共享该脚本,这种情况很少而且应该存在。
也许有更好的方法编写它,但到目前为止它仍在工作。
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" }