Brandon,
I get 2 strange results when I run the script at the ps command line
as ". .\names.ps1". First, after the script stops the last message
from it is:
Export-Csv : Cannot bind argument to parameter 'InputObject' because
it is null.
At C:\scripts\names6.ps1:44 char:27
+ $myColleciton | Export-Csv <<<< C:\scripts\testfile.csv
And second when I check the the contents of the variable $mycollection
I get the last computer checked over and over... not the whole
collection as expected:
ADName
NetworkName User
------
----------- ----
RIGHTFAX RIGHTFAX
RIGHTFAX RIGHTFAX
RIGHTFAX RIGHTFAX
RIGHTFAX RIGHTFAX
Hope you can help, I know I am missing something obvious.

Here is
the script in it's current form:
#gets all computers in AD using the Quest AD cmdlet
$comp = get-qadcomputer | sort-object
#counts the total computers in AD
$count = $comp.count
##################
#Create a generic Collection Obj
$myCollection = @()
##################
############
# Create Custom Object
$myobj = "" | select ADName,NetworkName,User
############
#screen display
"Computes in Active Directory = " + $count
"AD Name, Network Name, User Name"
#Foreach loop to check logged in users in domain.
#Displays results on screen and adds results to the array
foreach ($i in $comp)`
{
$CS = Gwmi Win32_ComputerSystem -Comp $I.name
$I.name + ", " + $CS.Name + ", " + $CS.UserName
##################
$myobj.ADName = $I.Name
$myobj.NetworkName = $CS.Name
$myobj.User = $CS.UserName
$myCollection += $myobj
##################
}
#################
$myColleciton | Export-Csv C:\scripts\testfile.csv
#################
On Aug 30, 4:01 pm, "Brandon Shell" <tshell.m...@xxxxxx> wrote:
> Maybe a better way to to do it is to create a custom objecthttp://bsonposh.com/modules/wordpress/?p=25
>
> Everything I added has ############ around it
>
> #gets all computers in AD using the Quest AD cmdlet
> $comp = get-qadcomputer | sort-object
>
> ##################
> #Create a generic Collection Obj
> $myCollection = @()
> ##################
>
> #counts the total computers in AD
> $count = ($comp | measure-object).count
>
> #creates a 2 dimensional array
> $table = new-object "string[,]" $count,3
>
> #screen display
> "AD Name, Network Name, User Name"
>
> #Foreach loop to check logged in users in domain.
> #Displays results on screen and adds results to the array
> foreach ($i in $comp)`
> {
> $CS = Gwmi Win32_ComputerSystem -Comp $I.name
> $I.name + ", " + $CS.Name + ", " + $CS.UserName
>
> #######################################
> # Create Custom Object
> $myobj = "" | select ADName,NetworkName,User
> #######################################
>
> $table[$inc,0] = $I.name
> $table[$inc,1] = $CS.Name
> $table[$inc,2] = $CS.UserName
>
> ##################
> $myobj.ADName = $I.Name
> $myobj.NetworkName = $CS.Name
> $myobj.User = $CS.UserName
> $myCollection += $myobj
> ##################
>
> }
>
> #################
> $myColleciton | Export-Csv C:\testfile.csv
> #################
>
> <jsimpson2...@xxxxxx> wrote in message
>
> news:1188503042.238763.257570@xxxxxx
>
>
>>
> > I am a system admin and I am a new to PowerShell and scripting in
> > general but I am getting to know it pretty quick. I have been
> > messing with a piece of code to get a list of all the computers is the
> > AD, then check those names and return the current logged on user.
> > here is the code I have so far: >
> > #gets all computers in AD using the Quest AD cmdlet
> > $comp = get-qadcomputer | sort-object >
> > #counts the total computers in AD
> > $count = ($comp | measure-object).count >
> > #creates a 2 dimensional array
> > $table = new-object "string[,]" $count,3 >
> > #counting variable
> > $inc = 0 >
> > #screen display
> > "AD Name, Network Name, User Name" >
> > #Foreach loop to check logged in users in domain.
> > #Displays results on screen and adds results to the array
> > foreach ($i in $comp)`
> > {
> > $CS = Gwmi Win32_ComputerSystem -Comp $I.name
> > $I.name + ", " + $CS.Name + ", " + $CS.UserName >
> > $table[$inc,0] = $I.name
> > $table[$inc,1] = $CS.Name
> > $table[$inc,2] = $CS.UserName >>
> > So I have two problems: First, When I display the array to the screen,
> > is comes out like this - >
> > ComputerName 1
> > ComputerName 1
> > UserName 1
> > ComputerName 2
> > ComputerName 2
> > UserName 2
> > ComputerName 3
> > ComputerName 3
> > UserName 3 >
> > Instead of like this - >
> > ComputerName 1 ComputerName 1 UserName 1
> > ComputerName 2 ComputerName 2 UserName 2
> > ComputerName 3 ComputerName 3 UserName 3 >
> > Also, I can not figure out how to pass this to Export-CSV. when I do I
> > get - >
> > Length
> > 0
> > 0
> > 0
> > 0
> > 0
> > 0
> > 12
> > 12
> > 11
> > 14
> > 18
> > 15
> > 9
> > 10 >
> > Hope someone can help. >
> > Thanks
> > Jim- Hide quoted text - >
> - Show quoted text -