none
PowerShell and XML RRS feed

  • Frage

  • Hey,

    I have a PowerShell script with input from a XML file.

    The location from the XML file is hard coded in the script.

    [xml]$XMLFile = get-content "Pfad to xml file"

    Is it possible not to hard code the path form the XML File in the script?

    I want to tell the script by calling it in the PowerShell command where the xml file are.

    How can I do this?

     

    Thanks for help

    Stefan


    Viele Grüße Stefan

    Kontakt unter Info@IT-Kiessig.de

    Freitag, 12. Oktober 2012 08:22

Antworten

  • Hallo Stefan,

    hier wird "deutsch" gesprochen bzw. geschrieben:-).

    Das kannst Du mit einem Param Block recht einfach realisieren:

    param(
        #Voller Pfad zur XML Datei
        [Parameter(Mandatory=$true)]
        [ValidateNOtNullOrEmpty()]
        [string] $Path
    )
    if(test-path $Path){
    #Dein Code
    
    }
    else{
    write-error "Bitte geben Sie den korrekten Pfad zur XML Datei an.
    }

    Das Skript wird dann so aufgerufen:

    .\deinskript.ps1 -path C:\test.xml

    Viele Grüße

    Frank


    -- Frank Röder http://blog.iteach-online.de --


    Freitag, 12. Oktober 2012 08:41