Powershell-Skript mit params *und* Funktionen

Ich möchte ein powershell-Skript schreiben, params und Funktionen nutzt.

Habe ich versucht, dieses:

param
(
  $arg
)

Func $arg;


function Func($arg)
{
  Write-Output $arg;
}

aber ich habe dieses:

The term 'Func' is not recognized as the name 
of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
At func.ps1:6 char:5
+ Func <<<<  $arg;
    + CategoryInfo          : ObjectNotFound: (Func:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Fein, dachte ich. Ich werde versuchen, dieses statt:

function Func($arg)
{
  Write-Output $arg;
}


param
(
  $arg
)

Func $arg;

Aber dann bekam ich diese:

The term 'param' is not recognized as the name 
of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
At C:\Users\akina\Documents\Work\ADDC\func.ps1:7 char:10
+     param <<<<
    + CategoryInfo          : ObjectNotFound: (param:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Ist, was ich Fragen, für machbar? Oder bin ich unvernünftig in meiner Anfrage?

Die Bestellung eines powershell-Skripts ist in der Regel, 1) Params, 2) Funktionen 3) - Funktion ruft/bestellt-cmdlets ausführen.
Christopher Ranney, das ist eine hilfreiche Zusammenfassung. Wenn Sie gepostet hatte dies als eine Frage, ich würde gestimmt haben, es bis.
Abstimmen können Sie Kommentare, wenn euer Herz so begehrt. 🙂

InformationsquelleAutor Tola Odejayi | 2013-02-15

Schreibe einen Kommentar