2012-07-18 11 views
8

Come posso recuperare il nome della funzione attualmente in esecuzione in PowerShell? Ecco un esempio di ciò che voglio:Visualizza il nome della funzione attualmente in esecuzione

Function write-FunctionName 
{ 
write-host "The name of this function is: *SomethingGoesHereButWhat?*" 
} 

Poi, quando eseguo esso, verrà visualizzato questo:

>write-FunctionName 

The name of this function is: write-FunctioName 

> 

si può fare? Se é cosi, come?

+1

Possibile duplicato di [C'è un modo per recuperare un nome di funzione di PowerShell all'interno di una funzione?] (Http://stackoverflow.com/questions/3689543/is-there-a-way-to-retrieve-a- powershell-function-name-from-within-a-function) –

risposta

9

La variabile $MyInvocation contiene informazioni su tutto ciò che è attualmente in esecuzione:

Function write-FunctionName 
{ 
    write-host ("The name of this function is: {0} " -f $MyInvocation.MyCommand) 
} 

Per ulteriori informazioni, vedere get-help about_automatic_variables, o il sito TechNet here.

+0

Grazie! Era esattamente quello che stavo cercando! – Winfred

Problemi correlati