First, as an FYI, best practice is to not utilize aliases in scripts.
I would suggest using get-wmiobject vs the gwmi alias.
Now to your real question, you are already retrieving multiple computers with your initial get-adcomputer line.
So, I’m going to make an assumption here that what you’re really asking is how to get all of your share reports out to a csv.
change this line:
$out >> c:\output.csv
to
$out |export-csv c:\output.csv -append -notypeinformation
as well, best practice is to not utilize aliases in scripts.
I would suggest using get-wmiobject vs the gwmi alias.
Agreed with the ‘Don’t use aliases in production scripts’. They are fine to save typing when doing interactive stuff at the console. You can use aliases in your script, but make sure you expand them before release. There ways to auto expand aliases.
Import-Module -Name ActiveDirectory
Depending on what OS you are on, this is done automatically, so no real to do this.
It does hurt by doing it, but, modules autoload on the system where they are installed. Again, OS and PSVersion withstanding.
No real need to declare variables, for stuff you are just going to pass down the pipeline.
Make use of default variables when / where possible.
$_ and $PSItem is the same thing. Use the information being passed down from the previous command.
No reason for all the semi-colons in PowerShell, except in specific scenarios. Like when you need to put stuff on one line that are distinct command, vs a tire one-liner that uses the pipeline. What you are doing, they are not needed. Though you will see it in many books, samples etc. This is an indication you / others are coming from another language, which is fine, but being new to PowerShell, be sure to spend the time getting ramped up to avoid frustration, confusion, misconceptions, mangling your code, errors, bad habits, etc. See the references to below.