Hei Lewandowski, Bartłomiej, Thank you for posting to Microsoft Q&A. I understand that you want the names and descriptions of the computers in your domain that match particular criteria. The criteria is, the property MemberOf for the resulting computer should not have a value that contains the string "GroupName". In addition, you are also trying to make a system with a switch case such that you can call multiple functions with the choice of user input. Currently, this system of switch case calls one function if the user enters 1, and on the second choice it exists. I tried the code, and i don't see much problem except that there is a bracket extra when you select name and description in the first line inside FunctionOne. The code I tried is listed below. A better approach maybe, if you want to create your own custom functions and use them later in scripts etc, try to create a module to house all those functions together. You can import all functions just by referencing that module file, more information: PowerShell Modules It makes it easier to maintain. If this solves your problem, do mark it as a response. If you have questions, do post a response with an error screenshot or message for reference. Sometimes the response gets mushed up in a giant paragraph, so I am posting the formatted text as a picture too
function MyFunctionOne {
$mycomps = Get-ADComputer -Filter * -Properties MemberOf, Description | Where-Object {[string]$_.MemberOf -notlike '*DKHOS-WSUS*'} | Select-Object -Property Name, Description
$mycomps.count()
}
function MyFunctionTwo {
Write-Host "Function 2"
}
function main {
$choice = 0
do {
$choice = Read-Host
switch($choice){
1 {MyFunctionOne break}
2 {MyFunctionTwo}
3 {$choice = 0}
}
}while($choice -ne 0)
}
main