{"id":22402188,"url":"https://github.com/tommyvange/printer-management-scripts","last_synced_at":"2025-10-25T04:43:40.707Z","repository":{"id":243017785,"uuid":"811241146","full_name":"tommyvange/Printer-Management-Scripts","owner":"tommyvange","description":"PowerShell scripts for installing, uninstalling, and verifying network printers on Windows, optimized for both manual and automated deployments like Intune. Licensed under GPLv3.","archived":false,"fork":false,"pushed_at":"2025-02-07T10:36:33.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-25T04:43:38.610Z","etag":null,"topics":["deployment","intune","powershell","printer","printer-management"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tommyvange.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-06T08:04:38.000Z","updated_at":"2025-02-07T10:36:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8907f17-9274-40c7-81b1-f77326e1d55f","html_url":"https://github.com/tommyvange/Printer-Management-Scripts","commit_stats":null,"previous_names":["tommyvange/printer-management-scripts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tommyvange/Printer-Management-Scripts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommyvange%2FPrinter-Management-Scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommyvange%2FPrinter-Management-Scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommyvange%2FPrinter-Management-Scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommyvange%2FPrinter-Management-Scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tommyvange","download_url":"https://codeload.github.com/tommyvange/Printer-Management-Scripts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tommyvange%2FPrinter-Management-Scripts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280906490,"owners_count":26411412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment","intune","powershell","printer","printer-management"],"created_at":"2024-12-05T09:11:39.149Z","updated_at":"2025-10-25T04:43:40.699Z","avatar_url":"https://github.com/tommyvange.png","language":"PowerShell","readme":"# Printer Management Scripts\r\n\r\nThese scripts are designed to install and uninstall network printers on Windows machines. They can read parameters from the command line, a configuration file (`config.json`), or use default values. If any required parameter is missing and cannot be resolved, the scripts will fail with an appropriate error message.\r\n\r\nThis repository is licensed under the **[GNU General Public License v3.0 (GPLv3)](LICENSE)**.\r\n\r\nCreated by **[Tommy Vange Rød](https://github.com/tommyvange)**. You can see the full list of credits [here](#credits).\r\n\r\n## Configuration\r\n\r\nThe scripts use a configuration file (`config.json`) to store default values for the printer settings. Here is an example of the configuration file:\r\n\r\n``` json\r\n{\r\n\t\"PrinterHostAddress\": \"111.22.33.444\",\r\n\t\"PortName\": \"IT_PRINT\",\r\n\t\"DriverName\": \"HP Universal Printing PCL 6\",\r\n\t\"PrinterName\": \"IT\",\r\n\t\"Logging\": true\r\n}\r\n```\r\n\r\n## Install Script\r\n\r\n### Description\r\n\r\nThe install script adds a printer port and a printer using the specified parameters. It checks if the port and printer already exist and takes appropriate actions to ensure they are correctly configured.\r\n\r\n### Usage\r\n\r\nTo run the install script, use the following command:\r\n``` powershell\r\n.\\install.ps1 -PrinterHostAddress \"\u003cPrinterHostAddress\u003e\" -PortName \"\u003cPortName\u003e\" -DriverName \"\u003cDriverName\u003e\" -PrinterName \"\u003cPrinterName\u003e\" [-Logging]\r\n```\r\n\r\n### Parameters\r\n-   `PrinterHostAddress`: The IP address of the printer.\r\n-   `PortName`: The name of the printer port.\r\n-   `DriverName`: The name of the printer driver.\r\n-   `PrinterName`: The name of the printer.\r\n-   [Optional] `Logging`: Enables transcript logging if set.\r\n\r\n### Fallback to Configuration File\r\n\r\nIf a parameter is not provided via the command line, the script will attempt to read it from the `config.json` file. If the parameter is still not available, the script will fail and provide an error message.\r\n\r\n### Example\r\nTo specify values directly via the command:\r\n``` powershell\r\n.\\install.ps1 -PrinterHostAddress \"111.22.33.555\" -PortName \"CUSTOM_PORT\" -DriverName \"Custom Driver\" -PrinterName \"Custom Printer\" [-Logging]\r\n```\r\n\r\nTo use the default values from the configuration file:\r\n``` powershell\r\n.\\install.ps1\r\n```\r\n\r\n### Script Workflow\r\n\r\n1.  Check if the printer port exists.\r\n2.  If the port exists, verify that it points to the correct IP address.\r\n3.  If the printer exists, remove it and its associated port.\r\n4.  Add the printer port if it doesn't exist or was just removed.\r\n5.  Add the printer.\r\n\r\n## Uninstall Script\r\n\r\n### Description\r\n\r\nThe uninstall script removes a specified printer and its associated port. It checks if the printer and port exist before attempting to remove them, ensuring no unnecessary errors are thrown. Additionally, it checks if any other printers are using the specified port and removes them before deleting the port.\r\n\r\n### Usage\r\n\r\nTo run the uninstall script, use the following command:\r\n``` powershell\r\n.\\uninstall.ps1 -PortName \"\u003cPortName\u003e\" -PrinterName \"\u003cPrinterName\u003e\" [-Logging]\r\n``` \r\n\r\n### Parameters\r\n\r\n-`PortName`: The name of the printer port.\r\n-`PrinterName`: The name of the printer.\r\n-[Optional] `Logging`: Enables transcript logging if set.\r\n\r\n### Fallback to Configuration File\r\n\r\nIf a parameter is not provided via the command line, the script will attempt to read it from the `config.json` file. If the parameter is still not available, the script will fail and provide an error message.\r\n\r\n### Example\r\nTo specify values directly via the command:\r\n``` powershell\r\n.\\uninstall.ps1 -PortName \"CUSTOM_PORT\" -PrinterName \"Custom Printer\" [-Logging]\r\n```\r\n\r\nTo use the default values from the configuration file:\r\n\r\n``` powershell\r\n.\\uninstall.ps1\r\n```\r\n\r\n\r\n### Script Workflow\r\n1.  Check if the printer exists.\r\n2.  If the printer exists, remove it.\r\n3.  Check if any other printers are using the specified port and remove them.\r\n4.  If the port exists, remove it.\r\n\r\n## Check Printer Script\r\n\r\n### Description\r\n\r\nThe check printer script verifies if a specified printer exists and outputs \"Detected\" or \"NotDetected\". It uses exit codes compatible with Intune: `0` for success (detected) and `1` for failure (not detected).\r\n\r\n### Usage\r\n\r\nTo run the check printer script, use the following command:\r\n``` powershell\r\n.\\check.ps1 -PrinterName \"\u003cPrinterName\u003e\" [-Logging]\r\n```\r\n\r\n#### Usage without `config.json` or Command Arguments\r\nIf you are running this as a check script in environments such as Intune, it is best to populate the variables directly in the code. Intune does not allow passing CLI arguments or using `config.json` for check scripts, so the only way is to set the variables within the script itself.\r\n\r\nThe script includes a section designed for this purpose:\r\n``` powershell\r\n# Manually fill these variables if using environments like Intune \r\n# (Intune does not support CLI arguments or configuration files for check scripts)\r\n#\r\n# $ManualPrinterName = \"PRINT (Color)\"\r\n# $ManualLogging = $false  # Set to $true to enable logging\r\n```\r\n\r\nTo use this feature, simply uncomment these lines and populate the variables with your desired values. The script will prioritize these manual settings over CLI arguments and config.json, ensuring that the specified data is used during execution. This approach allows seamless integration with Intune and similar deployment tools.\r\n\r\n\r\n\r\n#### Detecting Printers via Registry (Intune)\r\nWhen deploying printer settings via Intune, it's often necessary to detect whether a specific printer is already installed on the target machines. This can be achieved by checking the registry for the presence of the printer. Here are the detailed steps and settings required to create a detection rule in Intune using the registry:\r\n\r\n##### Rule Type: Registry\r\n\r\n1.  **Rule Type**: Registry\r\n\r\n##### Key Path\r\n\r\n-   **Key Path**: `HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Printers\\\u003cPRINTER NAME\u003e`\r\n    -   Replace `\u003cPRINTER NAME\u003e` with the actual name of the printer you want to detect.\r\n\r\n##### Value Name\r\n\r\n-   **Value Name**: `Name`\r\n\r\n##### Detection Method\r\n\r\n-   **Detection Method**: String comparison\r\n\r\n##### Operator\r\n\r\n-   **Operator**: Equals\r\n\r\n##### Value\r\n\r\n-   **Value**: `\u003cPRINTER NAME\u003e`\r\n    -   Replace `\u003cPRINTER NAME\u003e` with the actual name of the printer.\r\n\r\n### Parameters\r\n-   `PrinterName`: The name of the printer to check.\r\n-   [Optional] `Logging`: Enables transcript logging if set.\r\n\r\n### Fallback to Configuration File\r\n\r\nIf a parameter is not provided via the command line, the script will attempt to read it from the `config.json` file. If the parameter is still not available, the script will fail and provide an error message.\r\n\r\n### Example\r\nTo specify values directly via the command:\r\n``` powershell\r\n.\\check.ps1 -PrinterName \"Custom Printer\" [-Logging $true]\r\n```\r\n\r\nTo use the default values from the configuration file:\r\n\r\n``` powershell\r\n.\\check.ps1\r\n```\r\n\r\n### Script Workflow\r\n1.  Check if the printer name is provided.\r\n2.  Start transcript logging if enabled.\r\n3.  Check if the printer exists.\r\n4.  Output \"Detected\" if the printer exists, otherwise output \"NotDetected\".\r\n\r\n## Logging\r\n\r\n### Description\r\n\r\nBoth the install and uninstall scripts support transcript logging to capture detailed information about the script execution. Logging can be enabled via the `-Logging` parameter or the configuration file.\r\n\r\n### How It Works\r\n\r\nWhen logging is enabled, the scripts will start a PowerShell transcript at the beginning of the execution and stop it at the end. This transcript will include all commands executed and their output, providing a detailed log of the script's actions.\r\n\r\n### Enabling Logging\r\n\r\nLogging can be enabled by setting the `-Logging` parameter when running the script, or by setting the `Logging` property to `true` in the `config.json` file.\r\n\r\n\r\n### Log File Location\r\n\r\nThe log files are stored in the temporary directory of the user running the script. The log file names follow the pattern:\r\n\r\n-   For the install script: `printer_install_log_\u003cPrinterName\u003e_\u003cPortName\u003e.txt`\r\n-   For the uninstall script: `printer_uninstall_log_\u003cPrinterName\u003e_\u003cPortName\u003e.txt`\r\n\r\nExample log file paths:\r\n\r\n-   `C:\\Users\\\u003cUsername\u003e\\AppData\\Local\\Temp\\printer_install_log_IT_IT_PRINT.txt`\r\n-   `C:\\Users\\\u003cUsername\u003e\\AppData\\Local\\Temp\\printer_uninstall_log_IT_IT_PRINT.txt`\r\n\r\n**System Account Exception**: When scripts are run as the System account, such as during automated deployments or via certain administrative tools, the log files will be stored in the `C:\\Windows\\Temp` directory instead of the user's local temporary directory.\r\n\r\n## Error Handling\r\n\r\nBoth scripts include error handling to provide clear messages when parameters are missing or actions fail. If any required parameter is missing and cannot be resolved, the scripts will fail with an appropriate error message.\r\n\r\n## Notes\r\n\r\n-   Ensure that you have the necessary permissions to add and remove printers and ports on the machine where these scripts are executed.\r\n-   The scripts assume that the printer driver specified is already installed on the machine.\r\n\r\n## Troubleshooting\r\n\r\nIf you encounter any issues, ensure that all parameters are correctly specified and that the printer driver is installed. Check the error messages provided by the scripts for further details on what might have gone wrong.\r\n\r\n## Credits\r\n\r\n### Author\r\n\r\n\u003c!-- readme: tommyvange -start --\u003e\n\u003ctable\u003e\n\t\u003ctbody\u003e\n\t\t\u003ctr\u003e\n            \u003ctd align=\"center\"\u003e\n                \u003ca href=\"https://github.com/tommyvange\"\u003e\n                    \u003cimg src=\"https://avatars.githubusercontent.com/u/28400191?v=4\" width=\"100;\" alt=\"tommyvange\"/\u003e\n                    \u003cbr /\u003e\n                    \u003csub\u003e\u003cb\u003eTommy Vange Rød\u003c/b\u003e\u003c/sub\u003e\n                \u003c/a\u003e\n            \u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\u003ctbody\u003e\n\u003c/table\u003e\n\u003c!-- readme: tommyvange -end --\u003e\r\n\r\nYou can find more of my work on my [GitHub profile](https://github.com/tommyvange) or connect with me on [LinkedIn](https://www.linkedin.com/in/tommyvange/).\r\n\r\n### Contributors\r\nHuge thanks to everyone who dedicates their valuable time to improving, perfecting, and supporting this project!\r\n\r\n\u003c!-- readme: contributors,tommyvange/- -start --\u003e\n\u003ctable\u003e\n\t\u003ctbody\u003e\n\t\u003ctbody\u003e\n\u003c/table\u003e\n\u003c!-- readme: contributors,tommyvange/- -end --\u003e\r\n\r\n# GNU General Public License v3.0 (GPLv3)\r\n\r\nThe  **GNU General Public License v3.0 (GPLv3)**  is a free, copyleft license for software and other creative works. It ensures your freedom to share, modify, and distribute all versions of a program, keeping it free software for everyone.\r\n\r\nFull license can be read [here](LICENSE) or at [gnu.org](https://www.gnu.org/licenses/gpl-3.0.en.html#license-text).\r\n\r\n## Key Points:\r\n\r\n1.  **Freedom to Share and Change:**\r\n    -   You can distribute copies of GPLv3-licensed software.\r\n    -   Access the source code.\r\n    -   Modify the software.\r\n    -   Create new free programs using parts of it.\r\n\t\r\n2.  **Responsibilities:**\r\n    -   If you distribute GPLv3 software, pass on the same freedoms to recipients.\r\n    -   Provide the source code.\r\n    -   Make recipients aware of their rights.\r\n\t\r\n3.  **No Warranty:**\r\n    -   No warranty for this free software.\r\n    -   Developers protect your rights through copyright and this license.\r\n\t\r\n4.  **Marking Modifications:**\r\n    -   Clearly mark modified versions to avoid attributing problems to previous authors.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftommyvange%2Fprinter-management-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftommyvange%2Fprinter-management-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftommyvange%2Fprinter-management-scripts/lists"}