Search code examples
arrayspowershellregistryprinters

How to query the objects in "Devices and Printers" into an array via PowerShell


I'm having trouble trying to query the items that are in Devices and Printers. The long run goal is to delete everything located in 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices' except the devices located in Devices and Printers.

Unless there is another way to do this, I just need an array of the items in "Devices and Printers".


Solution

  • You can discover commands with Get-Command or gcm.

    This should get you going...

    C:\WINDOWS\system32> gcm *printer*
    
    CommandType     Name                                               Version    Source                                                                                     
    -----------     ----                                               -------    ------                                                                                     
    Function        Add-Printer                                        1.1        PrintManagement                                                                            
    Function        Add-PrinterDriver                                  1.1        PrintManagement                                                                            
    Function        Add-PrinterPort                                    1.1        PrintManagement                                                                            
    Function        Get-Printer                                        1.1        PrintManagement                                                                            
    Function        Get-PrinterDriver                                  1.1        PrintManagement                                                                            
    Function        Get-PrinterPort                                    1.1        PrintManagement                                                                            
    Function        Get-PrinterProperty                                1.1        PrintManagement                                                                            
    Function        Read-PrinterNfcTag                                 1.1        PrintManagement                                                                            
    Function        Remove-Printer                                     1.1        PrintManagement                                                                            
    Function        Remove-PrinterDriver                               1.1        PrintManagement                                                                            
    Function        Remove-PrinterPort                                 1.1        PrintManagement                                                                            
    Function        Rename-Printer                                     1.1        PrintManagement                                                                            
    Function        Set-Printer                                        1.1        PrintManagement                                                                            
    Function        Set-PrinterProperty                                1.1        PrintManagement                                                                            
    Function        Write-PrinterNfcTag                                1.1        PrintManagement                                                                            
    Cmdlet          Out-Printer                                        3.1.0.0    Microsoft.PowerShell.Utility                                                               
    
    
    
    C:\WINDOWS\system32> Get-Printer
    
    Name                           ComputerName    Type         DriverName                PortName        Shared   Published  DeviceType     
    ----                           ------------    ----         ----------                --------        ------   ---------  ----------     
    Send To OneNote 2016                           Local        Send to Microsoft OneN... nul:            False    False      Print          
    Microsoft XPS Document Writer                  Local        Microsoft XPS Document... PORTPROMPT:     False    False      Print          
    Microsoft Print to PDF                         Local        Microsoft Print To PDF    PORTPROMPT:     False    False      Print          
    Fax                                            Local        Microsoft Shared Fax D... SHRFAX:         False    False      Print          
    ...
    ...