2010-04-02 19 views

risposta

4

Purtroppo non :-(Attualmente i comandi PowerShell sono finalizzate a un più alto livello di granularità.

Tuttavia ...

È possibile scrivere i propri cmdlet di PowerShell, in modo da poter aggiungere quelle extra bisogno :-)

Ci sono molte informazioni sul web su writing custom cmdlets ma come guida approssimativa sarà qualcosa di simile. Costruisci un nuovo progetto Libreria di classi nella tua lingua preferita. Aggiungi un riferimento a System.Management.Automation.dll: lo puoi trovare in C: \ Programmi \ Reference Files \ Microsoft \ PowerShell \ 1.0. Creare una classe che eredita da Cmdlete ha anche l'attributo Cmdlet. Sostituisci il metodo ProcessRecord e aggiungi il codice per fare ciò che devi fare. Per passare i parametri da PowerShell è necessario aggiungere proprietà alla classe e contrassegnarli con l'attributo Parameter. Dovrebbe essere simile a questa:

Imports System.Management.Automation 
Imports Microsoft.ApplicationServer.Caching 

<Cmdlet(VerbsCommon.Remove, "CacheItem")> _ 
Public Class RemoveCacheItem 
    Inherits Cmdlet 

    Private mCacheName As String 
    Private mItemKey As String 

    <Parameter(Mandatory:=True, Position:=1)> _ 
    Public Property CacheName() As String 
     Get 
      Return mCacheName 
     End Get 
     Set(ByVal value As String) 
      mCacheName = value 
     End Set 
    End Property 

    <Parameter(Mandatory:=True, Position:=2)> _ 
    Public Property ItemKey() As String 
     Get 
      Return mItemKey 
     End Get 
     Set(ByVal value As String) 
      mItemKey = value 
     End Set 
    End Property 

    Protected Overrides Sub ProcessRecord() 

     MyBase.ProcessRecord() 

     Dim factory As DataCacheFactory 
     Dim cache As DataCache 

     Try 
      factory = New DataCacheFactory 

      cache = factory.GetCache(Me.CacheName) 

      Call cache.Remove(Me.ItemKey) 
     Catch ex As Exception 
      Throw 
     Finally 
      cache = Nothing 
      factory = Nothing 
     End Try 

    End Sub 

End Class 

Una volta che hai costruito la DLL, è possibile aggiungere in PowerShell con il cmdlet Import-Module.

+0

@PhilPursglove - Grazie. Qualche idea su come iniziare a usare Powershell per Appfabric? Ci sono libri o tutorial per guidare un principiante nel processo? – DotnetDude

+0

@DotNetDude Dai un'occhiata a http://mdcadmintool.codeplex.com/ -it è una GUI che si trova in cima ai comandi di PowerShell – PhilPursglove

Problemi correlati