0

It may be a stupid question, but I just start my journey with PowerShell.

What I'm trying to archive is to create Input-like cmdlt in PowerShell, the same as in Python. By that, I mean that I search for cmdlt that will execute something like this:

searched_user = str(input('Please input your AD user name: '))

but in PowerShell

Read-Host is not sufficient for my needs. I understand and treat it like print in Python.

I tried Read-Host but this is good for prompting something.

5
  • Not an answer, but just a general pointer. You can read the help items for powershell right in your browser. Example is, Help Read-Host. Commented Dec 29, 2022 at 11:34
  • Read-Host does support prompting the user; see Microsoft Learn on Read-Host Commented Dec 29, 2022 at 12:39
  • Why is Read-Host "not sufficient" for your needs? What is it that input() does that Read-Host doesn't? Commented Dec 29, 2022 at 14:33
  • @MichaelMao are you directing this comment to me? Because it is unclear for me. Commented Dec 30, 2022 at 9:08
  • @Gveir Sorry. It's my operation mistake Commented Dec 30, 2022 at 9:19

1 Answer 1

1

I see that you added Read-Host is off limits. However I would still like you to look if this example would point you to right direction:

$serverName = Read-Host -Prompt 'Server name to process'
if ($serverName) {
    Write-Host "We can now use the server name [$serverName] in our code"
} else {
    Write-Warning -Message "No server name input."
}

Source

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. Well, I manage to solve my mystery with simple solution. It looks like this: $searched_ad_user = Read-Host -Prompt 'Input your AD user namer here: ' $users = Get-AdUser -Identity $searched_ad_user -Properties DirectReports | Select-Object -ExpandProperty DirectReports

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.