Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Bu örnek, yerel bilgisayardaki işlemleri alan bir cmdlet'in nasıl uygulandığını gösterir. İşlem hattından bir nesneyi veya özellik adı parametre adıyla aynı olan bir nesnenin özelliğinden bir değeri kabul edebilen bir Name parametresi sağlar. Bu cmdlet, Windows PowerShell 2.0 tarafından sağlanan Get-Process cmdlet'in basitleştirilmiş bir sürümüdür.
Visual Studio kullanarak örnek oluşturma
Windows PowerShell 2.0 SDK'sı yüklü olarak GetProcessSample03 klasörüne gidin. Varsayılan konum
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0\Samples\sysmgmt\WindowsPowerShell\csharp\GetProcessSample03.Çözüm (.sln) dosyasının simgesine çift tıklayın. Bu işlem örnek projeyi Visual Studio'da açar.
Derleme menüsünde Çözümü Derle 'ı seçerek varsayılan
\binveya\bin\debugklasörlerinde örneğin kitaplığını oluşturun.
Örneği çalıştırma
Aşağıdaki modül klasörünü oluşturun:
[user]\Documents\WindowsPowerShell\Modules\GetProcessSample03Örnek derlemeyi modül klasörüne kopyalayın.
Windows PowerShell’i başlatın.
Derlemeyi Windows PowerShell'e yüklemek için aşağıdaki komutu çalıştırın:
Import-Module getprossessample03Cmdlet'ini çalıştırmak için aşağıdaki komutu çalıştırın:
Get-Proc
Gereksinimler
Bu örnek Için Windows PowerShell 2.0 gerekir.
Gösterir
Bu örnekte aşağıdakiler gösterilmektedir.
Cmdlet özniteliğini kullanarak bir cmdlet sınıfı bildirme.
Parameter özniteliğini kullanarak bir cmdlet parametresi bildirme.
Parametresinin konumunu belirtme.
parametresinin işlem hattından giriş aldığını belirtme. Giriş, bir nesneden veya özellik adı parametre adıyla aynı olan bir nesnenin özelliğinden alınabilir.
Parametre girişi için doğrulama özniteliği bildiriyor.
Örnek
Bu örnek, işlem hattından giriş kabul eden bir Name parametresi içeren Get-Proc cmdlet'in uygulamasını gösterir.
namespace Microsoft.Samples.PowerShell.Commands
{
using System;
using System.Diagnostics;
using System.Management.Automation; // Windows PowerShell namespace
#region GetProcCommand
/// <summary>
/// This class implements the Get-Proc cmdlet.
/// </summary>
[Cmdlet(VerbsCommon.Get, "Proc")]
public class GetProcCommand : Cmdlet
{
#region Parameters
/// <summary>
/// The names of the processes retrieved by the cmdlet.
/// </summary>
private string[] processNames;
/// <summary>
/// Gets or sets the names of the
/// process that the cmdlet will retrieve.
/// </summary>
[Parameter(
Position = 0,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string[] Name
{
get { return this.processNames; }
set { this.processNames = value; }
}
#endregion Parameters
#region Cmdlet Overrides
/// <summary>
/// The ProcessRecord method calls the Process.GetProcesses
/// method to retrieve the processes specified by the Name
/// parameter. Then, the WriteObject method writes the
/// associated processes to the pipeline.
/// </summary>
protected override void ProcessRecord()
{
// If no process names are passed to the cmdlet, get all
// processes.
if (this.processNames == null)
{
WriteObject(Process.GetProcesses(), true);
}
else
{
// If process names are passed to the cmdlet, get and write
// the associated processes.
foreach (string name in this.processNames)
{
WriteObject(Process.GetProcessesByName(name), true);
}
} // End if (processNames ...)
} // End ProcessRecord.
#endregion Overrides
} // End GetProcCommand.
#endregion GetProcCommand
}
Ayrıca Bkz.
PowerShell