Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell PS脚本,带有用于输入的弹出窗口_Powershell_User Interface - Fatal编程技术网

Powershell PS脚本,带有用于输入的弹出窗口

Powershell PS脚本,带有用于输入的弹出窗口,powershell,user-interface,Powershell,User Interface,我对PS很陌生。。我正在尝试为outlook邮箱还原创建脚本,在该脚本中,我可以将数据输入到弹出窗口中。。例如,当我运行此脚本时 新建MailboxRestoreRequest-SourceDatabase“dbname”-SourceStoreMailbox“GUID”-TargetMailbox“RECDBNAME”-AllowLegacyDnmatch-TargetRotFolder“用户名”-名称“名称” 我希望脚本弹出,询问sourcedatabase,然后是sourcestoreem

我对PS很陌生。。我正在尝试为outlook邮箱还原创建脚本,在该脚本中,我可以将数据输入到弹出窗口中。。例如,当我运行此脚本时

新建MailboxRestoreRequest-SourceDatabase“dbname”-SourceStoreMailbox“GUID”-TargetMailbox“RECDBNAME”-AllowLegacyDnmatch-TargetRotFolder“用户名”-名称“名称”


我希望脚本弹出,询问sourcedatabase,然后是sourcestoreemailbox,然后是targetmailbox,然后是targetroot文件夹,我已经使用read host命令进行了尝试,但没有任何运气。。。。请提供帮助。

就像mjolinor说的那样-将其设置为高级功能,您将获得所需的功能。它不会弹出一个窗口,尽管与PS 2.0对Read Host的方式相同(可能只有PS 2.0 ISE这样做了,我不记得了),但会在运行时询问用户输入

有关高级功能的帮助:

Get-Help about_Functions_Advanced
两个简单且简化的示例(使用PowerShell 3.0),展示了行为上的一些差异

function Test-Stuff {
Param($TestParameter)
    Write-Output "Testing $TestParameter"
}
输出:

C:\>测试材料

测试

C:\>

第二个示例将在运行时提示用户输入

function Test-Stuff
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        $TestParameter
    )

    Write-Output "Testing $TestParameter"
}
输出:

C:\>测试材料

命令管道位置1处的cmdlet测试内容

提供以下参数的值:

TestParameter:这个东西

测试这些东西

C:\>


为什么不让它成为一个高级函数,并将其声明为强制参数?如果函数调用中没有包含这些值,PS将提示您输入这些值。或者如果您使用v2.0或更早版本,则会将param默认值设置为Read Host语句:$myParam=(Read Host“请输入一些值”)