Unfortunately what you found is a really bad example ... actually for how to do it NOT. Sorry. You should not proceed with it. Something like this could be a starting point
function Get-DirectReports {
[CmdletBinding()]
[OutputType([System.String])]
param(
[Parameter(ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[System.String[]]
$Name
)
}
process {
Get-ADUser -Identity $user -Properties directreports |
Select-Object -Property Name,DirectReports
}
Get-DirectReports 'User1','User2' | Format-Table -AutoSize
Get-DirectReports 'User1','User2' | Out-File -FilePath C:\Sample\Direct.txt
Get-DirectReports 'User1','User2' | Export-Csv -Path C:\Sample\Direct.csv -Delimiter ',' -NoTypeInformation
It shows you how to create a function with a param block and how to format and export your output.
But actually you should stop by in the
Microsoft Technet Script Library or in the
Powershell Gallery. I'm pretty sure there a some scripts doing at least almost exactly what you're trying to create new ..... ;-) ... no need to re-invent the wheel.
Best regards,
(79,108,97,102|%{[char]$_})-join''