Function 显示菜单提示并将用户选择说明另存为powershell脚本中的变量

Function 显示菜单提示并将用户选择说明另存为powershell脚本中的变量,function,powershell,variables,Function,Powershell,Variables,不幸的是,他不是一个很有能力的人。希望实现以下目标: Prompt the user with a list of choices: 1 - gaming 2 - Home Ent 3 - Theatrical 4 - TV and Streaming 5 - VR 然后,给定用户响应(1-5),它将类型保存为变量(即,如果用户选择3,则变量($projectType)将保存为“戏剧”的选择描述 脚本的其余部分创建广告组、目录结构并设置权限。我已经了解了这一部分,但菜单提示暗示了我 我一直在

不幸的是,他不是一个很有能力的人。希望实现以下目标:

Prompt the user with a list of choices: 
1 - gaming
2 - Home Ent
3 - Theatrical
4 - TV and Streaming
5 - VR
然后,给定用户响应(1-5),它将类型保存为变量(即,如果用户选择3,则变量($projectType)将保存为“戏剧”的选择描述

脚本的其余部分创建广告组、目录结构并设置权限。我已经了解了这一部分,但菜单提示暗示了我

我一直在和PromptForChoice混日子,但失败得很惨

提前谢谢

编辑:根据Vasil的建议,我知道我有:

Function Get-ProjectType {
    $type=Read-Host "
    1 - gaming
    2 - Home Ent
    3 - Theatrical
    4 - TV and Streaming
    5 - VR
    Please choose Project Type"
    Switch ($type){
        1 {$projectType="Gaming"}
        2 {$projectType="Home Entertainment"}
        3 {$projectType="Theatrical"}
        4 {$projectType="TV & Streaming"}
        5 {$projectType="VR"}
    }
    return $projectType
}

#import the ActiveDirectory Module and define the parent folder path

Import-Module ActiveDirectory
$path = "\\calamedia\edit\$ProjectType"
 $newProjectName = Read-Host -Prompt "Enter Name of Project"
 $newFolderFull = $path + $newProjectName
 Write-Output "New Folder will be: $NewProjectName"
 $confirm = Read-Host "Confirm? Y/N"
 If(($confirm) -ne "y")
 {
     # End
 }
 Else
 {}

 Write-Output "Create AD Groups"
$groupnameRW = "Shared.$newProjectName.RW"
$groupnameR = "Shared.$newProjectName.R"
New-AdGroup $groupNameRW -samAccountName $groupNameRW -GroupScope DomainLocal -path "OU=Projects,OU=Managed Groups,DC=createadvertising,DC=com"
New-AdGroup $groupNameR -samAccountName $groupNameR -GroupScope DomainLocal -path "OU=Projects,OU=Managed Groups,DC=createadvertising,DC=com"

# add the folder itself and remove inherited permissions

Write-Output "Add Folder.."
New-Item $newProjectName -ItemType Directory
Write-Output "Remove Inheritance.."
icacls $newFolderFull /inheritance:d
但是,现在它似乎直接跳转到脚本后面的“输入项目名称:”提示,并且不显示函数的任何内容?

Update 我现在看到了您的代码,我已经以您可以应用的方式编辑了我的代码示例

您可以使用
读取主机
放置一些文本,并使用
开关
获取choose变量

Function Get-ProjectType {
    $type=Read-Host "
    1 - gaming
    2 - Home Ent
    3 - Theatrical
    4 - TV and Streaming
    5 - VR
    Please choose"
    Switch ($type){
        1 {$choice="Gaming"}
        2 {$choice="Home Entertainment"}
        3 {$choice="Theatrical"}
        4 {$choice="TV & Streaming"}
        5 {$choice="VR"}
    }
    return $choice
}

$projectType=Get-ProjectType

现在,
$projectType
包含了所选的名称。

您只需使用
写主机
$var=Read主机
我有一个函数,可以生成一个外观不错的菜单。还有一些示例代码说明如何使用它。尝试一下……直接复制并粘贴到我的脚本中,但它似乎跳过了这个完整部分,现在转到下一部分?在原始问题中添加我的新代码并添加注释您是一位英雄。谢谢