I am trying to get a Menu’s output to work properly with a Variable I have setup for querying an AD OU and using the results for -ComputerName. I will place the code and one of the variables I have setup and where I try to use it.
$Title = "Get WinRM status" $Message = "Please choose the Ou you like the status of" $Example1 = New-Object System.Management.Automation.Host.ChoiceDescription "Example1", ` "You have selected Example1." $Example2 = New-Object System.Management.Automation.Host.ChoiceDescription "EXample2", ` "You have selected Example2." $options = [System.Management.Automation.Host.ChoiceDescription[]]($Example1, $Example2) $result = $host.ui.PromptForChoice($title, $message, $options, 0) switch ($result) { 0 {"You selected Example1."} 1 {"You selected Example2."} Get-Service -ComputerName $result -Name WinRM | Select-Object -Property MachineName, Name, DisplayName, StartType, Status | export-csv -Path \\mycomputer\c$\WinRM.csv
Then I use this code to query OU.
$Example = Get-ADComputer -Filter * -SearchBase "OU=example, OU=PC, DC=Site, DC=com" | ForEach-Object {$_.Name}The Get-ADComputer script is loaded whenever I open powershell with the profile. I need to link the example1 and 2(and I need to rename them so they don't replace the Get-ADComputer commands) with the Get-ADComputer and then feed that into the -ComputerName. I hope I have explained this clearly and would appreciate any help that anyone has. Thank you