вернуть значение из функции, создающей поле ввода в powershell, но это значение кажется пустым - PullRequest
0 голосов
/ 22 февраля 2019

Моя функция создает поле ввода.

function name-label {
    # Incorporate Visual Basic into script
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

    # show the Pop Up with the following text.
    $label = [Microsoft.VisualBasic.Interaction]::InputBox("Pas plus de 11 caractères`r`n`
    1) Que des lettres ou des chifres`
    2) Pas de caractères bizarres comme $ * µ %", "Nom de la clef USB", "")

    if ($label -eq "") {
        # OK or Cancel button pushed with no input
        Write-Host "Vous venez d'appuyer sur OK ou ANNULER avec un nom de volume vide" -ForegroundColor Red -BackgroundColor Black

        # Open new popup with the folloing text
        [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
        $answer = [System.Windows.Forms.MessageBox]::Show("Voulez-vous vraiment annuler ?", "Annuler ?", 4, "question")

        if ($answer -eq "YES") {
            # Yes button selected for cancel
            Write-Host "Projet annuler par l'utilisateur" -ForegroundColor Green -BackgroundColor Black
            exit     # Quit the program
        } else {
            # You selected no, open a new pop up window withe the following text
            $a = New-Object -ComObject WScript.Shell
            $intAnswer = $a.Popup("Vous n'avez pas entrer un nom pour la clé USB`r `n Nouvel essai !",0,"ERROR!",0)
            name-label # Restart function
        }
    }

    $label
}
name-label
Write-Host '---======---' $label   # This is what is returned from the function

Переменная $label кажется пустой в Write-Host.Я не понимаю, почему и где моя проблема.

Так, как вернуть правильное значение?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...