powershell - 有没有办法通过智能卡通过powershell远程激活Windows?
问题描述
出于某种原因,我们的域没有 KMS 服务器设置。所以我们被迫手动激活窗口。这仅适用于 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" }
推荐阅读
- apache-superset - 使用 Apache Superset 启用自定义错误页面(例如 404)的最佳方法是什么?
- html - 使用右对齐或左对齐的最佳方式
- date - 如何在数组公式中添加带有 where 日期条件的查询?
- java - ProgressDialog android studio的模糊背景
- php - 将此 XML 数据转换为 JSON 格式的最简单方法
- zapier - 将 API 与 Zapier 一起使用,但获取“应用程序返回”“rest_data”参数不正确。需要 JSON 数据“。”
- postgresql - 在 Postgres 表中使用时区保存日期时间
- rust - 有什么方法或方法可以检查 Near 帐户 ID 上的 accesskey 权限吗?
- javascript - JavaScript 函数奇怪行为(函数调用)
- c# - Unity 调用返回值