Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Function and returned values

$
0
0

I have a function, listed below, that basically receives a list computer names and uses those values to identify all local profiles on such computers. These profiles (which basically is a string with several lines) then gets returned.

My issue is that I only get back the first line, or just one profile, instead of the entire list.

Basically, this is what $profile.LocalPath contains:

C:\Users\training01
C:\Users\glexp2
C:\Users\Administrator
C:\Windows\ServiceProfiles\NetworkService
C:\Windows\ServiceProfiles\LocalService
C:\WINDOWS\system32\config\systemprofile

I'd like to be able to return all these lines back to the calling portion.

This is how I'm calling that function:  $profilesFound = ListProfilesOnRemoteComputer ($machineName)

Thanks in advance!

Function ListProfilesOnRemoteComputer ($machineName)
{
    $foundProfiles = Get-WmiObject Win32_UserProfile -ComputerName $machineName

    # Initialize profile array
    $profile = @()
    
    ForEach ($profile in $foundProfiles)
    {
        return ,$profile.LocalPath
    }
}



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>