This...
$Printers = Get-Printer *
Foreach ($Printer in $Printers){Get-PrintConfiguration -PrinterName $Printer.name}
... can be simplified to this...
Get-Printer |
Foreach {Get-PrintConfiguration -PrinterName $PSItem.name}
Use the help file to know what is/is not available before you begin
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-Printer).Parameters
(Get-Command -Name Get-Printer).Parameters.Keys
# Results
<#
Name
ComputerName
Full
CimSession
ThrottleLimit
AsJob
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable
#>
Get-help -Name Get-Printer -Examples
Get-help -Name Get-Printer -Full
Get-help -Name Get-Printer -Online
(Get-Command -Name Get-PrintConfiguration).Parameters
(Get-Command -Name Get-PrintConfiguration).Parameters.Keys
# Results
<#
ComputerName
PrinterName
PrinterObject
CimSession
ThrottleLimit
AsJob
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable
#>
Get-help -Name Get-PrintConfiguration -Examples
Get-help -Name Get-PrintConfiguration -Full
Get-help -Name Get-PrintConfiguration -Online
# Get all data about one printer
Get-Printer |
Select-Object -First 1 |
Select-Object -Property '*'
# Results
<#
RenderingMode :
PrinterStatus : Normal
Type : Local
DeviceType : Print
Caption :
Description :
ElementName :
InstanceID :
CommunicationStatus :
DetailedStatus :
HealthState :
InstallDate :
Name : OneNote for Windows 10
OperatingStatus :
OperationalStatus :
PrimaryStatus :
Status :
StatusDescriptions :
BranchOfficeOfflineLogSizeMB :
Comment :
ComputerName :
Datatype : RAW
DefaultJobPriority : 0
DisableBranchOfficeLogging :
DriverName : Microsoft Software Printer Driver
JobCount : 0
KeepPrintedJobs : False
Location :
PermissionSDDL :
PortName : Microsoft.Office.OneNote_1600...
PrintProcessor : winprint
Priority : 1
Published : False
SeparatorPageFile :
Shared : False
ShareName :
StartTime : 0
UntilTime : 0
WorkflowPolicy :
PSComputerName :
CimClass : ROOT/StandardCimv2:MSFT_Printer
CimInstanceProperties : {Caption...
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
#>
Get-Printer |
Select-Object -First 1 |
Foreach {
Get-PrintConfiguration -PrinterName $PSItem.name |
Select-Object -Property '*'
}
# Results
<#
DuplexingMode : OneSided
PaperSize : Letter
Collate : True
Color : True
ComputerName :
PrintCapabilitiesXML : <?xml version="1.0"?>
<...
PrinterName : OneNote for Windows 10
PrintTicketXML : <?xml version="1.0"?>
...
PSComputerName :
CimClass : ROOT/StandardCimv2:MSFT_PrinterConfiguration
CimInstanceProperties : {Collate, Color, ComputerName, DuplexingMode, PaperSize, PrintCapabilitiesXML, PrinterName, PrintTicketXML}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
#>
You need to select the stuff you want, then combine together using a hash-table or custom object. Now that is not day one stuff, but again, many articles/blogs/videos, samples/examples on combining cmdlet output is plentiful.
PowerShell combine cmdlet output
https://duckduckgo.com/?q=PowerShell+combine+cmdlet+output&t=h_&ia=web
Example:
Get-Printer |
Select-Object -First 1 |
Select-Object -Property Name, DriverName, PortName, Comment, Location,
@{
Name = 'Color'
Expression = {(Get-PrintConfiguration -PrinterName $PSItem.Name).Color}
},
@{
Name = 'DuplexingMode '
Expression = {(Get-PrintConfiguration -PrinterName $PSItem.Name).DuplexingMode }
}
# Results
<#
Name : OneNote for Windows 10
DriverName : Microsoft Software Printer Driver
PortName : Microsoft.Office.OneNote_16001.13801.20202.0_x64__8wekyb3d8bbwe_microsoft.onenoteim_S-1-5-21-3258886415-1034932420-179337933-1002
Comment :
Location :
Color : True
DuplexingMode : OneSided
#>
To get all your printers, remove this line...
Select-Object -First 1 |
... no ForLoop required for your use case.
The above could also be written this way if you want to compress the number of lines.
Get-Printer | Select-Object -Property Name, DriverName, PortName, Comment, Location,
@{Name = 'Color';Expression = {(Get-PrintConfiguration -PrinterName $PSItem.Name).Color}},
@{Name = 'DuplexingMode';Expression = {(Get-PrintConfiguration -PrinterName $PSItem.Name).DuplexingMode}}
# Results
<#
Name : OneNote for Windows 10
DriverName : Microsoft Software Printer Driver
PortName : Microsoft.Office.OneNote_16001.13801.20202.0_x64__8wekyb3d8bbwe_microsoft.onenoteim_S-1-5-21-3258886415-1034932420-179337933-1002
Comment :
Location :
Color : True
DuplexingMode : OneSided
...
Name : Microsoft XPS Document Writer
DriverName : Microsoft XPS Document Writer v4
PortName : PORTPROMPT:
Comment :
Location :
Color : True
DuplexingMode : OneSided
Name : Microsoft Print to PDF
DriverName : Microsoft Print To PDF
PortName : PORTPROMPT:
Comment :
Location :
Color : True
DuplexingMode : OneSided
Name : Fax
DriverName : Microsoft Shared Fax Driver
PortName : SHRFAX:
Comment :
Location :
Color : False
DuplexingMode : OneSided
...
#>
Yet, I just find that harder to read. But that is just me. The use of natural line breaks, like '|', ';', ::
', comparison operators and others just allow for making things more humanly readable.
$Printers
collection? try usingGet-Member
... [grin]