Share via

Powershell - object return

Anonymous
2023-04-12T07:26:08+00:00

Hello, I made a simple program that print specified computers in our Domain, sadly there is a problem with returning an object from a function after call. First call does not work, 2nd print same output 2 times. Do you have any idea how to display it in a first run? As far as i know it is a problem that get-ad makes object and objects are not so eazy to return from function.

function MyFunctionOne{

    $Computers=(Get-ADComputer -Filter * -Properties MemberOf,description | Where-Object {[STRING]$_.MemberOf -notlike "*GroupName*"} | Select name, Description )

    return $Computers 

}
function main{

$choice = 0

Import-Module -Global -Name ActiveDirectory

Import-Module -Global -Name Microsoft.PowerShell.Utility // I though It was problem with module so I import it before execute command

    do{

        $choice = Read-Host

        switch($choice){

        1 {MyFunctionOne break}

        2 {$choice = 0}

        }

    }while($choice -ne 0)

}

main

Windows for home | Windows 10 | Settings

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. John DeV 164.9K Reputation points Independent Advisor
    2023-04-12T07:58:48+00:00

    Hello Lewandowski,

    Good day! I'm John DeV a Windows user like you and I'll be happy to assist you today.

    Due to the scope of your question, it is best to ask this on Microsoft Site Q&A which is a technical community platform where most of the members were IT professionals that would greatly help you with the issue.

    Microsoft Site Q&A

    https://learn.microsoft.com/en-us/answers/quest...

    Kind regards,

    John DeV

    Independent Advisor

    Was this answer helpful?

    0 comments No comments