Hi there,
I'm reaching out to you because I need some help to finish my script. I hope you can point me into the right direction.
It's one thing to execute the command on the console, but another thing to gather the data from hundreds of PCs and put it into a csv file :/
What should my script do?
It should run on the users computer, when the user does logon and gather information about installed printers and write/append the result to a csv file with the following information: Hostname, Username, Printername, Date of execution.
I've build an array and I almost got the result I want, with the exception that where I do expect the "printername" I get "Printer=System.Object[]". At this point I'm kind of stuck.
Thanks in advanced for your help!
Best wishes,
Mr_S
My Code:
$Printers = Get-Printer | ? shared -eq $true
$Date = Get-Date -Format dd.MM.yy
# New Array
$results = New-Object System.Collections.ArrayList
# Import Printerobjects
$Printer = $Printers
# Repeat command for each line
Foreach ($line in $Printer)
{
$results = New-Object psObject -Property @{'Computer'=$env:COMPUTERNAME;'Printer'=$Printers.Name;'User'=$env:USERNAME;'LastRun'=$Date;}
}
write-host $results
Result:
@{Printer=System.Object[]; User=Mr_s; Computer=PC001; LastRun=07.04.14}