بدء عملية ضمن مستخدم
الوصف
يوضح هذا المثال كيف يمكنك استخدام WindowsProcess
المورد لضمان تشغيل عملية ضمن حساب معين.
تتم مطالبتك ببيانات اعتماد إذا لم تقم بتمرير واحدة بشكل صريح باستخدام معلمة بيانات الاعتماد . يتم تعيين خاصية Credential للمورد إلى هذه القيمة.
مع تعيين Ensure إلى Present
، وتعيين المسار إلى C:\Windows\System32\gpresult.exe
، وتعيين الوسيطات إلى /h C:\gp2.htm
، يبدأ gpresult.exe
المورد بالوسيطات المحددة إذا لم يكن قيد التشغيل. نظرا لتعيين الخاصية Credential ، يبدأ المورد العملية مثل هذا الحساب.
مع Invoke-DscResource
يوضح هذا البرنامج النصي كيف يمكنك استخدام WindowsProcess
المورد مع Invoke-DscResource
cmdlet للتأكد من gpresult.exe
أنه يعمل مع الوسيطات /h C:\gp2.htm
كحساب محدد من قبل المستخدم.
[CmdletBinding()]
param(
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = (Get-Credential)
)
begin {
$SharedParameters = @{
Name = 'WindowsFeatureSet'
ModuleName = 'PSDscResource'
Properties = @{
Path = 'C:\Windows\System32\gpresult.exe'
Arguments = '/h C:\gp2.htm'
Credential = $Credential
Ensure = 'Present'
}
}
$NonGetProperties = @(
'Ensure'
)
}
process {
$TestResult = Invoke-DscResource -Method Test @SharedParameters
if ($TestResult.InDesiredState) {
$QueryParameters = $SharedParameters.Clone()
foreach ($Property in $NonGetProperties) {
$QueryParameters.Properties.Remove($Property)
}
Invoke-DscResource -Method Get @QueryParameters
} else {
Invoke-DscResource -Method Set @SharedParameters
}
}
مع تكوين
توضح هذه القصاصة البرمجية كيف يمكنك تعريف Configuration
مع كتلة WindowsProcess
موارد للتأكد من gpresult.exe
تشغيل مع الوسيطات /h C:\gp2.htm
كحساب محدد من قبل المستخدم.
Configuration StartUnderUser {
[CmdletBinding()]
param(
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = (Get-Credential)
)
Import-DSCResource -ModuleName 'PSDscResources'
Node localhost {
WindowsProcess ExampleWindowsProcess {
Path = 'C:\Windows\System32\gpresult.exe'
Arguments = '/h C:\gp2.htm'
Credential = $Credential
Ensure = 'Present'
}
}
}
الملاحظات
https://aka.ms/ContentUserFeedback.
قريبًا: خلال عام 2024، سنتخلص تدريجيًا من GitHub Issues بوصفها آلية إرسال ملاحظات للمحتوى ونستبدلها بنظام ملاحظات جديد. لمزيد من المعلومات، راجعإرسال الملاحظات وعرضها المتعلقة بـ