الهامه تم إيقاف هذه المقالة التي تحتوي على نموذج البرنامج النصي هذا. بدءا من تحديثات Windows التي تم إصدارها في 12 مايو 2026 وبعده، يوجد نموذج البرنامج النصي في المجلد ٪systemroot٪\SecureBoot\ExampleRolloutScripts على جهازك.

انسخ هذا البرنامج النصي النموذجي والصقه وقم بتعديله حسب الحاجة لبيئتك:

<# . خلاصه     تمكين المهمة المجدولة لتحديث التمهيد الآمن.

.DESCRIPTION     يضمن هذا البرنامج النصي مهمة Windows Secure Boot Update المجدولة     تم تمكين (\Microsoft\Windows\PI\Secure-Boot-Update). إذا تم تعطيله،     فإنه يمكن ذلك. إذا تم حذف المهمة، فيمكنها إعادة إنشائها.

.PARAMETER Action     الإجراء المطلوب تنفيذه. القيم الصالحة: التحقق من القيم وتمكينها وإنشاءها     - التحقق: تحقق فقط من حالة المهمة     - تمكين: (افتراضي) تمكين المهمة إذا تم تعطيلها. إذا كانت المهمة مفقودة، يطالبك بإنشائها.- إنشاء: إنشاء المهمة إذا لم تكن موجودة

.PARAMETER ComputerName     الاختياري. صفيف من أسماء الكمبيوتر للتحقق من المهمة/تمكينها.إذا لم يتم تحديده، يتم تشغيله على الجهاز المحلي.

.PARAMETER Credential     الاختياري. بيانات الاعتماد للوصول إلى الكمبيوتر عن بعد.

.PARAMETER Quiet     يمنع المطالبات ويجيب تلقائيا نعم. مفيد للأتمتة.

.EXAMPLE     .\Enable-SecureBootTask.ps1     # تمكين حالة المهمة على الجهاز المحلي

.EXAMPLE     تمكين .\Check-SecureBootScheduledTask.ps1     # تمكين المهمة إذا تم تعطيلها. الطلبات إلى إنشاء إذا كان مفقودا.

.EXAMPLE     إنشاء .\Check-SecureBootScheduledTask.ps1     # إنشاء المهمة إذا تم حذفها، ثم التحقق من حالتها

.EXAMPLE     .\Check-SecureBootScheduledTask.ps1 check -ComputerName "PC1", "PC2"     # التحقق من المهمة على الأجهزة البعيدة

.NOTES     يتطلب امتيازات المسؤول لتمكين المهمة أو إنشائها.مسار المهمة: \Microsoft\Windows\PI\Secure-Boot-Update     يتم تشغيل المهمة taskhostw.exe كل 12 ساعة بامتيازات مرتفعة.#>

[CmdletBinding(SupportsShouldProcess)] param(     [Parameter(Position=0)]     [ValidateSet('check', 'enable', 'create', '')]     [string]$Action = "enable"،

    [Parameter()]     [string[]]$ComputerName،

    [Parameter()]     [PSCredential]$Credential،

    [Parameter()]     [الاسم المستعار('Force', 'Silent')]     [switch]$Quiet )

# Convert Action to switches for backward compatibility $Enable = $Action -eq 'enable' $Create = $Action -eq "create"

# Download URL: https://aka.ms/getsecureboot -> "Deployment and Monitoring Samples" # ملاحظة: يتم تشغيل هذا البرنامج النصي على نقاط النهاية لتمكين مهمة تحديث التمهيد الآمن.

$TaskPath = "\Microsoft\Windows\PI\" $TaskName = "Secure-Boot-Update"

function Get-SecureBootTaskStatus {     [CmdletBinding()]     param(         [string]$Computer = $env:COMPUTERNAME     )

    $result = [PSCustomObject]@{         ComputerName = $Computer         TaskExists = $false         TaskState = $null         IsEnabled = $false         LastRunTime = $null         NextRunTime = $null         خطأ = $null     }

    try {         if ($Computer -eq $env:COMPUTERNAME -or $Computer -eq "localhost" -or $Computer -eq ".") {             # استخدم schtasks.exe للكشف عن المهام الأكثر موثوقية             $schtasksOutput = schtasks.exe /Query /TN "$TaskPath$TaskName" /FO CSV 2>&1                          إذا ($LASTEXITCODE -ne 0) {                 # المهمة التي لم يتم العثور عليها ليست خطأ - ما يعني فقط أن المهمة غير موجودة                 $result. TaskExists = $false                 إرجاع $result             }                          # تحليل إخراج CSV             $taskData = $schtasksOutput | ConvertFrom-Csv             if ($taskData) {                 $result. TaskExists = $true                 $result. TaskState = $taskData.Status                 $result. IsEnabled = ($taskData.Status -eq 'Ready' -or $taskData.Status -eq 'Running')                                  # حاول الحصول على وقت التشغيل التالي من البيانات                 if ($taskData.'Next Run Time' -and $taskData.'Next Run Time' -ne 'N/A') {                     جرب {                         $result. NextRunTime = [DateTime]::P arse($taskData.'Next Run Time')                     } التقاط { }                 }             }         }         آخر {             # الكمبيوتر البعيد - استخدام Invoke-Command مع المخططات             $remoteResult = Invoke-Command -ComputerName $Computer -ScriptBlock {                 param($fullTaskName)                 $output = schtasks.exe /Query /TN $fullTaskName /FO CSV 2>&1                 @{                     ExitCode = $LASTEXITCODE                     الإخراج = $output                 }             } -ArgumentList "$TaskPath$TaskName" -ErrorAction Stop

            if ($remoteResult.ExitCode -ne 0) {                 # المهمة التي لم يتم العثور عليها ليست خطأ - ما يعني فقط أن المهمة غير موجودة                 $result. TaskExists = $false                 إرجاع $result             }

            $taskData = $remoteResult.Output | ConvertFrom-Csv             إذا ($taskData) {                 $result. TaskExists = $true                 $result. TaskState = $taskData.Status                 $result. IsEnabled = ($taskData.Status -eq 'Ready' -or $taskData.Status -eq 'Running')             }         }     }     catch {         $result. خطأ = $_. استثناء.رسالة     }

    return $result }

function New-SecureBootTask {     [CmdletBinding(SupportsShouldProcess)]     param(         [string]$Computer = $env:COMPUTERNAME     )

    $success = $false     $errorMsg = $null

    # Task definition - matches the original Windows Secure Boot Update task     # يستخدم ComHandler مع فئة SBServicing، يعمل ك LocalSystem     $taskXml = @" <?xml version="1.0" encoding="UTF-16"?> <إصدار المهمة="1.6" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">  >معلومات تسجيل <     تاريخ <>2012-02-07T16:39:20</Date>     <SecurityDescriptor>O:BAG:BAD:P(A;; Fa;;; BA)(A;; Fa;;; SY)(A;; FRFX;;; LS)</SecurityDescriptor>    >مصدر <'$(@٪SystemRoot٪\system32\TpmTasks.dll,-601)</Source>     <Author>'$(@٪SystemRoot٪\system32\TpmTasks.dll,-600)</Author>     <الوصف>'$(@٪SystemRoot٪\system32\TpmTasks.dll,-604)</Description>     <URI>\Microsoft\Windows\PI\Secure-Boot-Update</URI>  ></RegistrationInfo  >كيانات <     <المعرف الأساسي="LocalSystem">       <UserId>S-1-5-18</UserId>     </> الأساسي  ></Principals  > إعدادات <     <عدم السماح بStartIfOnBatteries>خطأ</disallowStartIfOnBatteries>     ><0 StopIfGoingOnBatteries></StopIfGoingOnBatteries>     ><4 ExecutionTimeLimit>PT1H</ExecutionTimeLimit>     ><8 MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>     <StartWhenAvailable>true</StartWhenAvailable>    ><IdleSettings       <StopOnIdleEnd>true</StopOnIdleEnd>       <RestartOnIdle>خطأ</RestartOnIdle>    ></IdleSettings     <UseUnifiedSchedulingEngine></UseUnifiedSchedulingEngine>  ></Settings  >مشغلات <    ><BootTrigger       <تأخير>PT5M</تأخير>      > التكرار <         الفاصل الزمني <>PT12H</Interval>       </>التكرار    ></BootTrigger  ></Triggers   سياق إجراءات <="LocalSystem">     <ComHandler>       <ClassId>{5014B7C8-934E-4262-9816-887FA745A6C4}</ClassId>      >< بيانات <! [CDATA[SBServicing]]></Data>    ></ComHandler  >/Actions < </> المهمة " @

    try {         if ($Computer -eq $env:COMPUTERNAME -or $Computer -eq "localhost" -or $Computer -eq ".") {             if ($PSCmdlet.ShouldProcess("$TaskPath$TaskName", "Create scheduled task")) {                 # حفظ XML إلى ملف مؤقت واستيراد                 $tempFile = [System.IO.Path]::GetTempFileName()                 $taskXml | Out-File -FilePath $tempFile -ترميز Unicode -Force                                  $output = schtasks.exe /إنشاء /TN "$TaskPath$TaskName" /XML $tempFile /F 2>&1                                  Remove-Item $tempFile -Force -ErrorAction SilentlyContinue                                  if ($LASTEXITCODE -eq 0) {                     $success = $true                 } آخر {                     $errorMsg = $output -join " "                 }             }         }         آخر {             if ($PSCmdlet.ShouldProcess("$Computer\$TaskPath$TaskName", "Create scheduled task")) {                 $result = Invoke-Command -ComputerName $Computer -ScriptBlock {                     param($taskPath, $taskName, $xml)                     $tempFile = [System.IO.Path]::GetTempFileName()                     $xml | Out-File -FilePath $tempFile -ترميز Unicode -Force                     $output = schtasks.exe /Create /TN "$taskPath$taskName" /XML $tempFile /F 2>&1                     Remove-Item $tempFile -Force -ErrorAction SilentlyContinue                     @{ ExitCode = $LASTEXITCODE؛ الإخراج = $output }                 } -ArgumentList $TaskPath، $TaskName، $taskXml -ErrorAction Stop                                  إذا ($result. ExitCode -eq 0) {                     $success = $true                 } آخر {                     $errorMsg = $result. Output -join " "                 }             }         }     }     catch {         $errorMsg = $_. استثناء.رسالة     }

    return @{         Success = $success         خطأ = $errorMsg     } }

function Enable-SecureBootTask {     [CmdletBinding(SupportsShouldProcess)]     param(         [string]$Computer = $env:COMPUTERNAME     )

    $success = $false     $errorMsg = $null

    try {         if ($Computer -eq $env:COMPUTERNAME -or $Computer -eq "localhost" -or $Computer -eq ".") {             if ($PSCmdlet.ShouldProcess("$TaskPath$TaskName", "Enable scheduled task")) {                 $output = schtasks.exe /Change /TN "$TaskPath$TaskName" /ENABLE 2>&1                 if ($LASTEXITCODE -eq 0) {                     $success = $true                 } آخر {                     $errorMsg = $output -join " "                 }             }         }         آخر {             if ($PSCmdlet.ShouldProcess("$Computer\$TaskPath$TaskName", "Enable scheduled task")) {                 $result = Invoke-Command -ComputerName $Computer -ScriptBlock {                     param($fullTaskName)                     $output = schtasks.exe /Change /TN $fullTaskName /ENABLE 2>&1                     @{ ExitCode = $LASTEXITCODE؛ الإخراج = $output }                 } -ArgumentList "$TaskPath$TaskName" -ErrorAction Stop                                  إذا ($result. ExitCode -eq 0) {                     $success = $true                 } آخر {                     $errorMsg = $result. Output -join " "                 }             }         }     }     catch {         $errorMsg = $_. استثناء.رسالة     }

    return @{         Success = $success         خطأ = $errorMsg     } }

# Main execution Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host " Secure Boot Update Task Enabler" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "المهمة: $TaskPath$TaskName" -ForegroundColor Gray Write-Host ""

# Determine target computers $targets = if ($ComputerName) { $ComputerName } else { @($env:COMPUTERNAME) }

$results = @()

foreach ($computer in $targets) {     Write-Host "Checking: $computer" -ForegroundColor Yellow     $status = Get-SecureBootTaskStatus -الكمبيوتر $computer     إذا ($status. خطأ) {         Write-Host " خطأ: $($status. خطأ)" -ForegroundColor Red     }     elseif (-not $status. TaskExists) {         Write-Host " المهمة غير موجودة على هذا النظام" -ForegroundColor Red         # إنشاء إذا طلب منك ذلك، أو المطالبة إذا تم تحديد تمكين         $shouldCreate = $Create         if (-not $shouldCreate -and $Enable) {             Write-Host ""             Write-Host " ربما تم حذف المهمة." -ForegroundColor Yellow             إذا ($Quiet) {                 Write-Host " مهمة الإنشاء التلقائي (وضع الهدوء)" -ForegroundColor Cyan                 $shouldCreate = $true             } آخر {                 $confirm = Read-Host " هل تريد إعادة إنشاء المهمة؟                    (Y/N)"                 إذا ($confirm -eq 'Y' -أو $confirm -eq 'y') {                     $shouldCreate = $true                 }             }         }                  إذا ($shouldCreate) {             Write-Host " إنشاء مهمة..." -ForegroundColor Yellow             $createResult = New-SecureBootTask -الكمبيوتر $computer                          if ($createResult.Success) {                 Write-Host "تم إنشاء المهمة بنجاح" -ForegroundColor Green                 # إعادة التحقق من الحالة                 $status = $computer الكمبيوتر Get-SecureBootTaskStatus                                  إذا ($status. TaskExists) {                     $stateColor = إذا ($status. IsEnabled) { "Green" } else { "Red" }                     Write-Host " State: $($status. TaskState)" -ForegroundColor $stateColor                 }             }             آخر {                 Write-Host " فشل الإنشاء: $($createResult.Error)" -ForegroundColor Red             }         }     }     آخر {         $stateColor = إذا ($status. IsEnabled) { "Green" } else { "Red" }         Write-Host " State: $($status. TaskState)" -ForegroundColor $stateColor                  إذا ($status. LastRunTime -and $status. LastRunTime -ne [DateTime]::MinValue) {             Write-Host " آخر تشغيل: $($status. LastRunTime)" -ForegroundColor Gray         }         إذا ($status. NextRunTime -and $status. NextRunTime -ne [DateTime]::MinValue) {             Write-Host " Next Run: $($status. NextRunTime)" -ForegroundColor Gray         }

        # Enable if requested and currently disabled         إذا ($Enable -و-not $status. IsEnabled) {             Write-Host " تمكين المهمة..." -ForegroundColor Yellow             $enableResult = Enable-SecureBootTask -الكمبيوتر $computer             if ($enableResult.Success) {                 Write-Host "تم تمكين المهمة بنجاح" -ForegroundColor Green                 # إعادة التحقق من الحالة                 $status = Get-SecureBootTaskStatus -الكمبيوتر $computer             }             آخر {                 Write-Host " فشل تمكين: $($enableResult.Error)" -ForegroundColor Red             }         }         elseif ($Enable -and $status. IsEnabled) {             Write-Host " تم تمكين المهمة بالفعل" -ForegroundColor Green         }     }     $results += $status     Write-Host "" }                  

# Summary Write-Host "========================================" -ForegroundColor Cyan Write-Host "Summary" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan

$enabled = ($results | Where-Object { $_.IsEnabled }).Count $disabled = ($results | Where-Object { $_. TaskExists -and -not $_. IsEnabled }). عدد $notFound = ($results | Where-Object { -not $_. TaskExists }). عدد $errors = ($results | Where-Object { $_. خطأ }). عدد

Write-Host "Total Checked: $($results.Count)" Write-Host "Enabled: $enabled" -ForegroundColor Green if ($disabled -gt 0) { Write-Host "Disabled: $disabled" -ForegroundColor Red } if ($notFound -gt 0) { Write-Host "Not Found: $notFound" -ForegroundColor Yellow } إذا ($errors -gt 0) { Write-Host "الأخطاء: $errors" -ForegroundColor Red }

# Return results for pipeline $results  

هل تحتاج إلى مزيد من المساعدة؟

الخروج من الخيارات إضافية؟

استكشف مزايا الاشتراك، واستعرض الدورات التدريبية، وتعرف على كيفية تأمين جهازك، والمزيد.