├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Images ├── WinGet-WrapperImportFromCSV.png ├── WinGet-WrapperImportGUI.png └── Winget-Wrapper.png ├── IntuneWinAppUtil.exe ├── LICENSE.txt ├── README.md ├── WinGet-Wrapper.intunewin ├── WinGet-Wrapper.ps1 ├── WinGet-WrapperDetection.ps1 ├── WinGet-WrapperImportFromCSV.csv ├── WinGet-WrapperImportFromCSV.ps1 ├── WinGet-WrapperImportGUI.exe ├── WinGet-WrapperImportGUI.ps1 ├── WinGet-WrapperRequirements.ps1 └── Winget-Wrapper.ico /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct - WinGet-Wrapper 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to a positive environment for our 15 | community include: 16 | 17 | * Demonstrating empathy and kindness toward other people 18 | * Being respectful of differing opinions, viewpoints, and experiences 19 | * Giving and gracefully accepting constructive feedback 20 | * Accepting responsibility and apologizing to those affected by our mistakes, 21 | and learning from the experience 22 | * Focusing on what is best not just for us as individuals, but for the 23 | overall community 24 | 25 | Examples of unacceptable behavior include: 26 | 27 | * The use of sexualized language or imagery, and sexual attention or 28 | advances 29 | * Trolling, insulting or derogatory comments, and personal or political attacks 30 | * Public or private harassment 31 | * Publishing others' private information, such as a physical or email 32 | address, without their explicit permission 33 | * Other conduct which could reasonably be considered inappropriate in a 34 | professional setting 35 | 36 | ## Our Responsibilities 37 | 38 | Project maintainers are responsible for clarifying and enforcing our standards of 39 | acceptable behavior and will take appropriate and fair corrective action in 40 | response to any instances of unacceptable behavior. 41 | 42 | Project maintainers have the right and responsibility to remove, edit, or reject 43 | comments, commits, code, wiki edits, issues, and other contributions that are 44 | not aligned to this Code of Conduct, or to ban 45 | temporarily or permanently any contributor for other behaviors that they deem 46 | inappropriate, threatening, offensive, or harmful. 47 | 48 | ## Scope 49 | 50 | This Code of Conduct applies within all community spaces, and also applies when 51 | an individual is officially representing the community in public spaces. 52 | Examples of representing our community include using an official e-mail address, 53 | posting via an official social media account, or acting as an appointed 54 | representative at an online or offline event. 55 | 56 | ## Enforcement 57 | 58 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 59 | reported to the community leaders responsible for enforcement at <>. 60 | All complaints will be reviewed and investigated promptly and fairly. 61 | 62 | All community leaders are obligated to respect the privacy and security of the 63 | reporter of any incident. 64 | 65 | ## Attribution 66 | 67 | This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org/), version 68 | [1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct/code_of_conduct.md) and 69 | [2.0](https://www.contributor-covenant.org/version/2/0/code_of_conduct/code_of_conduct.md), 70 | and was generated by [contributing-gen](https://github.com/bttger/contributing-gen). -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributing to WinGet-Wrapper 3 | 4 | First off, thanks for taking the time to contribute! ❤️ 5 | 6 | All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉 7 | 8 | > And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: 9 | > - Star the project 10 | > - Tweet about it 11 | > - Refer this project in your project's readme 12 | > - Mention the project at local meetups and tell your friends/colleagues 13 | 14 | 15 | ## Table of Contents 16 | 17 | - [Code of Conduct](#code-of-conduct) 18 | - [I Have a Question](#i-have-a-question) 19 | - [I Want To Contribute](#i-want-to-contribute) 20 | - [Reporting Bugs](#reporting-bugs) 21 | - [Suggesting Enhancements](#suggesting-enhancements) 22 | - [Your First Code Contribution](#your-first-code-contribution) 23 | - [Improving The Documentation](#improving-the-documentation) 24 | - [Styleguides](#styleguides) 25 | - [Commit Messages](#commit-messages) 26 | - [Join The Project Team](#join-the-project-team) 27 | 28 | 29 | ## Code of Conduct 30 | 31 | This project and everyone participating in it is governed by the 32 | [WinGet-Wrapper Code of Conduct](https://github.com/SorenLundt/WinGet-Wrapperblob/master/CODE_OF_CONDUCT.md). 33 | By participating, you are expected to uphold this code. Please report unacceptable behavior 34 | to <>. 35 | 36 | 37 | ## I Have a Question 38 | 39 | > If you want to ask a question, we assume that you have read the available [Documentation](https://github.com/SorenLundt/WinGet-Wrapper/blob/main/README.md). 40 | 41 | Before you ask a question, it is best to search for existing [Issues](https://github.com/SorenLundt/WinGet-Wrapper/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first. 42 | 43 | If you then still feel the need to ask a question and need clarification, we recommend the following: 44 | 45 | - Open an [Issue](https://github.com/SorenLundt/WinGet-Wrapper/issues/new). 46 | - Provide as much context as you can about what you're running into. 47 | - Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. 48 | 49 | We will then take care of the issue as soon as possible. 50 | 51 | 65 | 66 | ## I Want To Contribute 67 | 68 | > ### Legal Notice 69 | > When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license. 70 | 71 | ### Reporting Bugs 72 | 73 | 74 | #### Before Submitting a Bug Report 75 | 76 | A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. 77 | 78 | - Make sure that you are using the latest version. 79 | - Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://github.com/SorenLundt/WinGet-Wrapper/blob/main/README.md). If you are looking for support, you might want to check [this section](#i-have-a-question)). 80 | - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/SorenLundt/WinGet-Wrapperissues?q=label%3Abug). 81 | - Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue. 82 | - Collect information about the bug: 83 | - Stack trace (Traceback) 84 | - OS, Platform and Version (Windows, Linux, macOS, x86, ARM) 85 | - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. 86 | - Possibly your input and the output 87 | - Can you reliably reproduce the issue? And can you also reproduce it with older versions? 88 | 89 | 90 | #### How Do I Submit a Good Bug Report? 91 | 92 | > You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to <>. 93 | 94 | 95 | We use GitHub issues to track bugs and errors. If you run into an issue with the project: 96 | 97 | - Open an [Issue](https://github.com/SorenLundt/WinGet-Wrapper/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.) 98 | - Explain the behavior you would expect and the actual behavior. 99 | - Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case. 100 | - Provide the information you collected in the previous section. 101 | 102 | Once it's filed: 103 | 104 | - The project team will label the issue accordingly. 105 | - A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced. 106 | - If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution). 107 | 108 | 109 | 110 | 111 | ### Suggesting Enhancements 112 | 113 | This section guides you through submitting an enhancement suggestion for WinGet-Wrapper, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions. 114 | 115 | 116 | #### Before Submitting an Enhancement 117 | 118 | - Make sure that you are using the latest version. 119 | - Read the [documentation](https://github.com/SorenLundt/WinGet-Wrapper/blob/main/README.md) carefully and find out if the functionality is already covered, maybe by an individual configuration. 120 | - Perform a [search](https://github.com/SorenLundt/WinGet-Wrapper/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. 121 | - Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library. 122 | 123 | 124 | #### How Do I Submit a Good Enhancement Suggestion? 125 | 126 | Enhancement suggestions are tracked as [GitHub issues](https://github.com/SorenLundt/WinGet-Wrapper/issues). 127 | 128 | - Use a **clear and descriptive title** for the issue to identify the suggestion. 129 | - Provide a **step-by-step description of the suggested enhancement** in as many details as possible. 130 | - **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you. 131 | - You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. 132 | - **Explain why this enhancement would be useful** to most WinGet-Wrapper users. You may also want to point out the other projects that solved it better and which could serve as inspiration. 133 | 134 | 135 | 136 | ### Your First Code Contribution 137 | 141 | 142 | ### Improving The Documentation 143 | 147 | 148 | ## Styleguides 149 | ### Commit Messages 150 | 153 | 154 | ## Join The Project Team 155 | 156 | 157 | 158 | ## Attribution 159 | This guide is based on the **contributing-gen**. [Make your own](https://github.com/bttger/contributing-gen)! 160 | -------------------------------------------------------------------------------- /Images/WinGet-WrapperImportFromCSV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/Images/WinGet-WrapperImportFromCSV.png -------------------------------------------------------------------------------- /Images/WinGet-WrapperImportGUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/Images/WinGet-WrapperImportGUI.png -------------------------------------------------------------------------------- /Images/Winget-Wrapper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/Images/Winget-Wrapper.png -------------------------------------------------------------------------------- /IntuneWinAppUtil.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/IntuneWinAppUtil.exe -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WinGet-Wrapper 2 | PowerShell Scripts to deploy and bulk import WinGet packages to InTune including metadata.
3 | Automatically detect latest version using dynamic detection script.
4 | Detection script checks local installed version against latest winget available version or a defined fixed target version.
5 | Bulk import WinGet packages to InTune including WinGet package metadata using WinGet-WrapperImportGUI.exe
6 |
7 | * Dynamically finds the WinGet directory to be used under System Context.
8 | * Kill selected process before WinGet command
9 | * Allows running pre and post script before installation
10 | * Detection script that dynamically finds latest package available trough WinGet
11 | * Requirement script to allow creating packages for update purposes only
12 | * Logs to $env:ProgramData\WinGet-WrapperLogs (Usually C:\ProgramData\WinGet-WrapperLogs)
13 | * Dynamically detect if running in user or system context
14 | * Performs automatic cleanup of log files older than 60 days.
15 | * Directly import and deploy WinGet packages to InTune including WinGet package metadata
16 | 17 | ## Background / Why? 18 | WinGet have a few limitations in terms of automation and is not integrated with common endpoints management products.
19 | System Context is not possible by using "winget" as the .exe location must be found and this location is not static due to versioning in the directory name.
20 | 21 | ## Requirements 22 | Windows 10 20H2 or newer
23 | Powershell 5.1
24 | Client language must be en-US, as Winget-Wrapper parses only English output.
25 | Module "IntuneWin32App" and "Microsoft.Graph.Intune" needed for import to InTune
26 | 27 | ## WinGet-WrapperImportGUI.exe 28 | WinGet-WrapperImportGUI is a graphical interface designed to streamline the import of WinGet packages into InTune.
29 | This tool complements WinGet-Wrapper, providing an intuitive way to upload WinGet packages to InTune, along with their metadata.
30 | 31 | #### Features: 32 | - **Search and Select:** Seamlessly search for WinGet packages, get detailed info and package versions. 33 | - **InTune Integration:** Import selected WinGet packages directly into InTune for deployment. 34 | - **CSV Support:** Export and import packages using CSV files, facilitating batch operations.
35 | 36 | ![image](Images/WinGet-WrapperImportGUI.png) 37 | 38 | 39 | #### Usage: 40 | >**Open the GUI:** Run WinGet-WrapperImportGUI.exe to open the GUI
41 | >**Search Packages:** Enter your search query and click "Search" to find WinGet packages.
42 | >**Select Packages:** Select from search results, then click the center arrow to move them to the import list.
43 | >**Adjust:** Select target version if required, UpdateOnly, Installation context, etc.
44 | >**Import to InTune:** Enter your Tenant ID and click "Import to InTune" to import selected packages.
45 | >**Additional Actions:** Use buttons for exporting CSV, deleting, or importing from CSV.
46 | 47 | 48 | ## WinGet-Wrapper.ps1 49 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/4220b44b-7f96-4fb1-84ec-ce416f6f622c) 50 | 51 | #### Usage: 52 | >Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName "PackageName for log file" -StopProcess "kill process using Stop-Process (do not add .exe)" -PreScript "somefile.ps1" -PostScript "somefile.ps1" -ArgumentList "Arguments Passed to WinGet.exe" 53 | 54 | ## WinGet-WrapperDetection.ps1 55 | Matches locally installed version with newest available version using WinGet or specified version using $TargetVersion
56 | Can be setup to accept newer installed version locally $AcceptNewerVersion

57 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/631d6001-b813-4b79-a12f-3c1e06cb3aec) 58 | 59 | ## WinGet-WrapperRequirements.ps1 60 | Checks if application is detected locally. If not detected will not attempt update/install
61 | To be used when only wanting to update if application is already installed. (Update Only)

62 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/b5af0ddd-6700-46cf-8907-33dbd0f8e930) 63 | 64 | Outputs either "Installed" or "Not Installed"

65 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/b8cd24fd-da34-4e1c-aeb2-0627717e1244) 66 | 67 | ## WinGet-WrapperImportFromCSV.ps1 68 | Imports packages from WinGet to InTune (incuding available WinGet package metadata)
69 | Package content is stored under Packages\Package.ID-Context-UpdateOnly-UserName-yyyy-mm-dd-hhssmm
70 | Create deployment using csv columns: InstallIntent, Notification, GroupID

71 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/dde433b9-81e1-484b-8ee1-71ac02d68441) 72 |
73 | ## Usage: Import from CSV (InTune) 74 | Open the sample CSV file WinGet-WrapperImportFromCSV.csv and add any WinGet Package IDs to import (Case Sensitive)
75 | #### Usage: 76 | >WinGet-WrapperImportFromCSV.ps1 -TenantID company.onmicrosoft.com -csvFile WinGet-WrapperImportFromCSV.csv -SkipConfirmation 77 | #### Process: 78 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/297ddb07-eeac-41c7-a9ec-9656727984f6) 79 |
80 | #### Results: 81 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/ca57c9d4-0ec7-4514-8694-7160f6356b5e) 82 | 83 | 84 | #### Columns: 85 | * PackageID = Exact PackageID (Required)
86 | * Context = Which context the Win32App is run under (Machine or User) (Required)
87 | * AcceptNewerVersion = Allows newer installed version locally than specified (Set to 0 or 1)(Required)
88 | * UpdateOnly = Update package only. Application will only update if application is already installed (Set to 0 or 1)(Required)
89 | * TargetVersion = Specfic version of the application. If not set, the package will always be the latest version
90 | * StopProcessInstall = Kill a specific process (Stop-process) before installation (.exe should not be defined)
91 | * StopProcessUninstall = Kill a specific process (Stop-process) before uninstallation (.exe should not be defined)
92 | * PreScriptInstall = Run powershell script before installation
93 | * PostScript = Run powershell script after installation
94 | * PreScriptUninstall = Run powershell script before uninstallation
95 | * PostScriptUninstall = Run powershell script after uninstallation
96 | * CustomArgumentListInstall = Arguments passsed to WinGet (default: install --exact --id PackageID --silent --accept-package-agreements --accept-source-agreements --scope Context
97 | * CustomArgumentListUninstall = Arguments passsed to WinGet (default: uninstall --exact --id PackageID --silent --accept-source-agreements --scope Context
98 | * InstallIntent = Available or Required deployment
99 | * Notification = Notification level on deployment - Valid values: showAll, showReboot, hideAll
100 | * GroupID = InTune GroupID to deploy package to
101 | 102 | 103 | ## Usage: Manual Import (InTune) 104 | **Application Installation** 105 | 106 | In InTune create an Windows app (Win32) and upload WinGet-Wrapper.InTuneWin as the package file.
107 | >**Install:** Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName "VideoLAN.VLC" -StopProcess "VLC" -ArgumentList "install --exact --id VideoLAN.VLC --silent --accept-package-agreements --accept-source-agreements --scope machine" 108 | 109 | >**Uninstall:** Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName "VideoLAN.VLC" -StopProcess "VLC" -ArgumentList "Uninstall --exact --id VideoLAN.VLC --silent --accept-source-agreements --scope machine" 110 | 111 | Change the $id variable to match the package id in the detection script and upload it ($id = "VideoLAN.VLC")
112 | *If specific version is required change the $TargetVersion (Ex. $TargetVersion = "1.0.0.0")*

113 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/2aea611c-7733-4f93-9cbe-a44b4f66333d) 114 | 115 | **Application Update Only** 116 | 117 | For creating application that will only update/install if application is already installed
118 | Perform the same steps as in "Application Installation".
119 | Setup Requirement rule script with return string value of "Installed"

120 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/b2bdb617-c74a-4902-9c2c-b8defe1adc70) 121 | 122 | ![image](https://github.com/SorenLundt/WinGet-Wrapper/assets/127216441/b8cd24fd-da34-4e1c-aeb2-0627717e1244) 123 | 124 | ## Is Winget Safe to Use in Enterprise?
125 | Winget (Windows Package Manager) is generally safe for enterprise use due to the following security features:
126 |
127 | * Package Verification: Utilizes hash checks to ensure package integrity.
128 | * Microsoft Vetting: Packages undergo thorough testing and scanning before approval.
129 | * Manual Approvals: Human oversight adds an extra layer of security.
130 | * User Controls: Enterprises can restrict installations through whitelisting.
131 | * Regular Updates: Active maintenance and community involvement enhance security.
132 |
133 | Overall, Winget is a secure option for enterprises, especially when proper management practices are implemented. Continuous monitoring is key to maintaining security.
134 | 135 | ## Disclaimer 136 | While Winget provides various security measures, no software management tool is entirely risk-free. Organizations should continually assess their security posture and policies when using Winget or any other software deployment tool.
137 |
138 | **This software is provided "AS IS" with no warranties. Use at your own risk.**
139 | -------------------------------------------------------------------------------- /WinGet-Wrapper.intunewin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/WinGet-Wrapper.intunewin -------------------------------------------------------------------------------- /WinGet-Wrapper.ps1: -------------------------------------------------------------------------------- 1 | # Soren Lundt - 22-02-2023 2 | # URL: https://github.com/SorenLundt/WinGet-Wrapper 3 | # License: https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/main/LICENSE.txt 4 | # Wrapper for running winget in system context. Finds the WinGet install path and runs desired command 5 | # 6 | # Usage: .\WinGet-Wrapper.ps1 -PackageName "Packagename used in log entry" -Context "User or System" -StopProcess "kill process using Stop-Process (.exe for the most part is not needed)" -ArgumentList "Arguments Passed to WinGet.exe" 7 | # INSTALL .\WinGet-Wrapper.ps1 -PackageName "VideoLAN.VLC" -StopProcess "VLC" -PreScript "Script1.ps1" -PostScript "Script2.ps1" -ArgumentList "install --exact --id VideoLAN.VLC --silent --accept-package-agreements --accept-source-agreements --scope machine" 8 | # UNINSTALL .\WinGet-Wrapper.ps1 -PackageName "VideoLAN.VLC" -StopProcess "VLC" -PreScript "Script1.ps1" -PostScript "Script2.ps1" -ArgumentList "Uninstall --exact --id VideoLAN.VLC --silent --accept-source-agreements --scope machine" 9 | # 10 | # Variables: 11 | # PackageName = Package name mainly used for naming the log file. 12 | # StopProcess = Kill a specific process (Stop-process) before executing WinGet command (.exe should not be defined) Skips any error automatically. 13 | # PreScript = Run powershell script before installation 14 | # PostScript = Run powershell script after installation 15 | # ArgumentList = Arguments passed directly to WinGet 16 | # 17 | # Version History 18 | # Version 1.0 - 22-02-2023 SorenLundt - Initial Version 19 | # Version 1.1 - 28-02-2023 SorenLundt - Added logging functionality and changed to use Invoke-Expression to get data written to prompt and log file 20 | # Version 1.2 - 01-03-2023 SorenLundt - Added logging of winget output + added PackageName parameter used in logging functionality 21 | # Version 1.3 - 02-03-2023 SorenLundt - Added stop process to kill any process before upgrading. No user warning is shown etc. 22 | # Version 1.4 - 26-05-2023 SorenLundt - Added support for context choice by adding $Context variable 23 | # Version 1.5 - 30-05-2023 SorenLundt - Fixed issues with running in user context (Winget path issues) 24 | # Version 1.6 - 24-08-2023 SorenLundt - Added automatically detection if running in user or system context. Decide context using deployment tools (InTune). Removing Context parameter 25 | # Version 1.7 - 24-08-2023 SorenLundt - Added support for running pre/post script before winget action + WindowStyle Hidden for winget process + Other small fixes.. 26 | # Version 1.8 - 13-11-2023 SorenLundt - Added proper logging function instead of using Start-Transscript (Github Issue #5) 27 | # Version 1.9 - 13-11-2023 SorenLundt - Improved log output and added $ScriptVersion variable 28 | 29 | #Parameters 30 | Param ( 31 | # PackageName = Package name mainly used for naming the log file. 32 | [Parameter(Mandatory=$true)] 33 | [string]$PackageName, 34 | 35 | # StopProcess = Kill a specific process (Stop-process) before executing WinGet command (.exe should not be defined) Skips any error automatically. 36 | [Parameter()] 37 | [string]$StopProcess, 38 | 39 | # PreScript = Run a script before installation 40 | [Parameter()] 41 | [string]$PreScript, 42 | 43 | # PostScript = Run a script after installation 44 | [Parameter()] 45 | [string]$PostScript, 46 | 47 | # ArgumentList = Arguments passed directly to WinGet 48 | [Parameter(Mandatory=$true)] 49 | [string]$ArgumentList 50 | ) 51 | 52 | #Define common variables 53 | $ScriptVersion = "1.9" 54 | $timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" 55 | $logPath = "$env:ProgramData\WinGet-WrapperLogs" 56 | $stdout = "$logPath\StdOut-$timestamp.txt" 57 | $errout = "$logPath\ErrOut-$timestamp.txt" 58 | 59 | # Create log folder 60 | if (!(Test-Path -Path $logPath)) { 61 | try { 62 | New-Item -Path $logPath -Force -ItemType Directory | Out-Null 63 | } 64 | catch { 65 | Write-Log "Failed to create log directory: $($_.Exception.Message)" 66 | exit 1 67 | } 68 | } 69 | 70 | function Write-Log { 71 | param ( 72 | [string]$Message, 73 | [string]$LogFile = "$logPath\$($PackageName)_WinGet_Wrapper_$($TimeStamp).log" 74 | ) 75 | 76 | $TimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" 77 | $LogEntry = "[$TimeStamp] $Message" 78 | 79 | # Output to the console 80 | Write-Host $LogEntry 81 | 82 | # Append to the log file 83 | $LogEntry | Out-File -Append -FilePath $LogFile 84 | } 85 | 86 | 87 | #Write useful variables to log 88 | Write-Log " WinGet-Wrapper v.$ScriptVersion" 89 | Write-Log "https://github.com/SorenLundt/WinGet-Wrapper" 90 | Write-Log " GNU General Public License v3" 91 | Write-Log "**************************************************" 92 | Write-Log "Host: $env:ComputerName" 93 | Write-Log "PackageName: $PackageName" 94 | Write-Log "StopProcess: $StopProcess" 95 | Write-Log "PreScript: $PreScript" 96 | Write-Log "PostScript: $PostScript" 97 | Write-Log "ArgumentList: $ArgumentList" 98 | Write-Log "LogPath: $logPath" 99 | Write-Log "**************************************************" 100 | 101 | #PreScript 102 | if (![string]::IsNullOrEmpty($PreScript)) { 103 | Write-Log "Running PreScript $PreScript" 104 | if (Test-Path $PreScript -PathType Leaf) { 105 | try { 106 | Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File $PreScript 107 | } catch { 108 | Write-Log "An error occurred while running the PreScript: $_" 109 | Write-Log "Exit 1" 110 | exit 1 111 | } 112 | } else { 113 | Write-Log "PreScript not found: $PreScript" 114 | Write-Log "Exit 1" 115 | exit 1 116 | } 117 | } 118 | 119 | #Stop process 120 | if (-not ($StopProcess -eq $null) -and $StopProcess -ne "") { 121 | Stop-Process -Name $StopProcess -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue 122 | Write-Log "Stopped process: $StopProcess" 123 | } 124 | 125 | #Determine if running in system or user context 126 | if ($env:USERNAME -like "*$env:COMPUTERNAME*") { 127 | Write-Log "Running in System Context" 128 | $Context = "Machine" 129 | } 130 | else { 131 | Write-Log "Running in User Context" 132 | $Context = "User" 133 | } 134 | 135 | # Find WinGet.exe Location 136 | if ($Context -contains "Machine"){ 137 | try { 138 | $resolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" 139 | if ($resolveWingetPath) { 140 | $wingetPath = $resolveWingetPath[-1].Path 141 | $wingetPath = $wingetPath + "\winget.exe" 142 | Write-Log "WinGet path: $wingetPath" 143 | } 144 | else { 145 | Write-Log "Failed to find WinGet path" 146 | exit 1 147 | } 148 | } 149 | catch { 150 | Write-Log "Failed to find WinGet path: $($_.Exception.Message)" 151 | exit 1 152 | } 153 | } 154 | else{ 155 | # Running in user context. Set WingetPath 156 | $wingetPath = "winget.exe" 157 | } 158 | 159 | Write-Log "Executing $wingetPath $ArgumentList" 160 | Start-Process "$WingetPath" -ArgumentList "$ArgumentList" -WindowStyle Hidden -PassThru -Wait -RedirectStandardOutput "$stdout" -RedirectStandardError "$errout" 161 | 162 | # Log the contents of the stdout and errout 163 | $stdoutContent = Get-Content "$stdout" 164 | $erroutContent = Get-Content "$errout" 165 | 166 | # Log the contents of the stdout and errout (single lines) 167 | $stdoutContent -split "`r`n" | ForEach-Object { 168 | Write-Log " $_" 169 | } 170 | $erroutContent -split "`r`n" | ForEach-Object { 171 | Write-Log " $_" 172 | } 173 | 174 | 175 | Remove-item -Path "$stdout" 176 | Remove-item -Path "$errout" 177 | 178 | #PostScript 179 | if (![string]::IsNullOrEmpty($PostScript)) { 180 | Write-Log "Running PostScript $PostScript" 181 | if (Test-Path $PostScript -PathType Leaf) { 182 | try { 183 | Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File $PostScript 184 | } catch { 185 | Write-Log "An error occurred while running the PostScript: $_" 186 | Write-Log "Exit 1" 187 | exit 1 188 | } 189 | } else { 190 | Write-Log "PostScript not found: $PostScript" 191 | Write-Log "Exit 1" 192 | exit 1 193 | } 194 | } 195 | 196 | Write-Log "Script Finished" -------------------------------------------------------------------------------- /WinGet-WrapperDetection.ps1: -------------------------------------------------------------------------------- 1 | # Soren Lundt - 22-02-2023 2 | # URL: https://github.com/SorenLundt/WinGet-Wrapper 3 | # License: https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/main/LICENSE.txt 4 | # Detection script to check if desired application is installed and/or application up to date compared to WinGet. 5 | # 6 | # Version History 7 | # Version 1.1 - 27-02-2023 SorenLundt - Updated to retrieve current version from WinGet and dynamically check for latest version and detect based. 8 | # Version 1.2 - 28-02-2023 SorenLundt - Added logging capability 9 | # Version 1.3 - 01-03-2023 SorenLundt/ChatGPT - Changed expression to properly find the local installed version. Issue that winget list also shows available version from winget 10 | # Version 1.4 - 01-03-2023 SorenLundt - Added section to cleanup old log files. 60 days. 11 | # Version 1.5 - 13-03-2023 SorenLundt - Overall added better error handling - try/catch - Write-Log 12 | # Version 1.6 - 13-03-2023 SorenLundt - Added functionality to report installed if locally installed version is newer than Available WinGet or TargetVersion. $AcceptNewerVersion 13 | # Version 1.7 - 14-03-2023 SorenLundt - Added functionality to auto update - fixes issue #1 on https://github.com/SorenLundt/WinGet-Wrapper. 14 | # Version 1.8 - 26-05-2023 SorenLundt - Added support for context choice by adding $Context variable 15 | # Version 1.9 - 30-05-2023 SorenLundt - Fixed issues with running in user context (Winget path issues) + Updated version regex to be more precise 16 | # Version 2.0 - 21-08-2023 SorenLundt - Removing AutoUpdate completely. Feature does not support InTune with "Available" deployments, as detection rules only runs periodically for "Required" deployments. 17 | # Version 2.1 - 22-08-2023 SorenLundt - Adding UpdateOnly. To be used when only wanting to update apps but not install if not detected. 18 | # Version 2.2 - 24-08-2023 SorenLundt - Removing UpdateOnly as this would lead to false positive, indicating that a given app was installed when actually it is not. 19 | # Version 2.3 - 24-08-2023 SorenLundt - Adding automatically detection if running in user or system context. Removing Context parameter 20 | # Version 2.4 - 24-08-2023 SorenLundt - WindowStyle Hidden for winget process + Other small fixes.. 21 | # Version 2.5 - 24-08-2023 SorenLundt - Added --scope $Context to winget cmd to avoid detecting applications in wrong context 22 | # Version 2.6 - 18-10-2023 SorenLundt - Added --accept-source-agreements when searching for latest winget package to avoid any prompts 23 | # Version 2.7 - 20-10-2023 SorenLundt - Fixed issues where applications containing + would not be detected.. Regex issue 24 | # Version 2.8 - 23-10-2023 SorenLundt - Convert version string to System.Version objects to properly compare Winget and Installed versions 25 | # Version 2.9 - 23-10-2023 SorenLundt - Updated version check segment + optimized detection by checking local installed version first 26 | # Version 3.0 - 24-10-2023 SorenLundt - Fixed issue where packages containing + would not be able to search on winget and small minor changes. 27 | # Version 3.1 - 27-10-2023 SorenLundt - Fixed issues with certain packages missing revision in version number, causing version mismatch compare to fail (ex. installed: 4.0.10 - Winget: 4.0.10.0) 28 | # Version 3.2 - 13-11-2023 SorenLundt - Fixed issues with packages with build number (GitHub issue #6) Added function to correct empty(-1) major, minor, build, revision. Sets it from -1 to 0 29 | # Version 3.3 - 13-11-2023 SorenLundt - Added proper logging function instead of using Start-Transscript (Github Issue #5) 30 | # Version 3.4 - 13-11-2023 SorenLundt - Minor issue. Wrong log filename, contained "Wrapper" instead of "Detection". Also now removing old *.txt files from log directory 31 | # Version 3.5 - 13-11-2023 SorenLundt - Improved log output and added $ScriptVersion variable 32 | 33 | # Settings 34 | $id = "Exact WinGet Package ID" # WinGet Package ID - ex. VideoLAN.VLC 35 | $TargetVersion = "" # Set if specific version is desired (Optional) 36 | $AcceptNewerVersion = "$True" # Allows locally installed versions to be newer than $TargetVersion or available WinGet package version 37 | # EndSettings 38 | 39 | #Define common variables 40 | $ScriptVersion = "3.5" 41 | $timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" 42 | $logPath = "$env:ProgramData\WinGet-WrapperLogs" 43 | $stdout = "$logPath\StdOut-$timestamp.txt" 44 | $errout = "$logPath\ErrOut-$timestamp.txt" 45 | 46 | # Create log folder 47 | if (!(Test-Path -Path $logPath)) { 48 | try { 49 | New-Item -Path $logPath -Force -ItemType Directory | Out-Null 50 | } 51 | catch { 52 | Write-Log "Failed to create log directory: $($_.Exception.Message)" 53 | exit 1 54 | } 55 | } 56 | 57 | function Write-Log { 58 | param ( 59 | [string]$Message, 60 | [string]$LogFile = "$logPath\$($id)_WinGet_Detection_$($TimeStamp).log" 61 | ) 62 | 63 | $TimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" 64 | $LogEntry = "[$TimeStamp] $Message" 65 | 66 | # Output to the console 67 | Write-Host $LogEntry 68 | 69 | # Append to the log file 70 | $LogEntry | Out-File -Append -FilePath $LogFile 71 | } 72 | 73 | #Write useful variables to log 74 | Write-Log " WinGet-WrapperDetection v.$ScriptVersion" 75 | Write-Log "https://github.com/SorenLundt/WinGet-Wrapper" 76 | Write-Log " GNU General Public License v3" 77 | Write-Log "**************************************************" 78 | Write-Log "Host: $env:ComputerName" 79 | Write-Log "PackageName: $id" 80 | Write-Log "TargetVersion: $TargetVersion" 81 | Write-Log "AcceptNewerVersion = $AcceptNewerVersion" 82 | Write-Log "LogPath: $logPath" 83 | Write-Log "**************************************************" 84 | 85 | 86 | # Clean log and txt files older than X days 87 | $daysToKeepLogs = 60 88 | $filesToDelete = Get-ChildItem $logPath -Recurse -Include *.log, *.txt | Where-Object LastWriteTime -lt (Get-Date).AddDays(-$daysToKeepLogs) 89 | try { 90 | $count = $filesToDelete.Count 91 | $filesToDelete | Remove-Item -Force | Out-Null 92 | if ($count -gt 0) 93 | { 94 | Write-Log "Cleaned up a total of $count old logs older than $daysToKeepLogs days." 95 | } 96 | } 97 | catch { 98 | Write-Log "Failed to delete old log files: $($_.Exception.Message)" 99 | } 100 | 101 | #Determine if running in system or user context 102 | if ($env:USERNAME -like "*$env:COMPUTERNAME*") { 103 | Write-Log "Running in System Context" 104 | $Context = "Machine" 105 | } 106 | else { 107 | Write-Log "Running in User Context" 108 | $Context = "User" 109 | } 110 | 111 | # Find WinGet.exe Location 112 | if ($Context -contains "Machine"){ 113 | try { 114 | $resolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" 115 | if ($resolveWingetPath) { 116 | $wingetPath = $resolveWingetPath[-1].Path 117 | $wingetPath = $wingetPath + "\winget.exe" 118 | Write-Log "WinGet path: $wingetPath" 119 | } 120 | else { 121 | Write-Log "Failed to find WinGet path" 122 | exit 1 123 | } 124 | } 125 | catch { 126 | Write-Log "Failed to find WinGet path: $($_.Exception.Message)" 127 | exit 1 128 | } 129 | } 130 | else{ 131 | # Running in user context. Set WingetPath 132 | $wingetPath = "winget.exe" 133 | } 134 | 135 | # Get latest version from WinGet 136 | if ($TargetVersion -eq $null -or $TargetVersion -eq '') { 137 | try { 138 | Start-Process -FilePath $wingetPath -ArgumentList "show --id $id --exact --accept-source-agreements" -WindowStyle Hidden -Wait -RedirectStandardOutput $stdout 139 | $winGetOutput = Get-Content -Path $stdout 140 | Remove-Item -Path $stdout -Force 141 | 142 | $TargetVersion = $winGetOutput | Select-String -Pattern "version:" | ForEach-Object { $_.Line -replace '.*version:\s*(.*)', '$1' } 143 | Write-Log "WinGet version: $TargetVersion" 144 | } 145 | catch { 146 | Write-Log "Failed to get latest version from WinGet: $($_.Exception.Message)" 147 | exit 1 148 | } 149 | }elseif ($TargetVersion -ne $null -and $TargetVersion -ne '') 150 | { Write-Host "TargetVersion: $TargetVersion (Set specific)"} 151 | 152 | 153 | # Get version installed locally on machine 154 | $InstalledVersion = $null # Clear Variable 155 | try { 156 | Start-Process -FilePath $wingetPath -ArgumentList "list $id --exact --accept-source-agreements --scope $Context" -WindowStyle Hidden -Wait -RedirectStandardOutput $stdout 157 | $searchString = Get-Content -Path $stdout 158 | Remove-Item -Path $stdout -Force 159 | 160 | # Remove + character from $id 161 | $searchString = $searchString -replace '\+', '' 162 | # Remove + character from $id 163 | $InstalledID = $id -replace '\+', '' 164 | 165 | $versions = [regex]::Matches($searchString, "(?m)^.*$InstalledID\s*(?:[<>]?[\s]*)([\d.]+).*?$").Groups[1].Value 166 | if ($versions) { 167 | $InstalledVersion = ($versions | sort {[version]$_} | select -Last 1) 168 | Write-Log "Installed version: $InstalledVersion" 169 | } 170 | else { 171 | Write-Log "Package not found - #exit 1" 172 | exit 1 173 | } 174 | } catch { 175 | Write-Log "Failed to get installed version: $($_.Exception.Message)" 176 | Write-Log "exit 1 - Report Not Installed" 177 | # Exit 1 - Report Not Installed$inst 178 | exit 1 179 | } 180 | 181 | 182 | # Convert version strings to System.Version objects 183 | $TargetVersion = [System.Version]::new($TargetVersion) 184 | $InstalledVersion = [System.Version]::new($InstalledVersion) 185 | 186 | # Function to set all version components to 0 if they are -1 187 | function SetVersion($version) { 188 | $major = if ($version.Major -eq -1) { 0 } else { $version.Major } 189 | $minor = if ($version.Minor -eq -1) { 0 } else { $version.Minor } 190 | $build = if ($version.Build -eq -1) { 0 } else { $version.Build } 191 | $revision = if ($version.Revision -eq -1) { 0 } else { $version.Revision } 192 | return [System.Version]::new($major, $minor, $build, $revision) 193 | } 194 | 195 | $InstalledVersion = SetVersion $InstalledVersion 196 | $TargetVersion = SetVersion $TargetVersion 197 | 198 | # Check versions 199 | if ($AcceptNewerVersion -eq $false -and $InstalledVersion -eq $TargetVersion) { 200 | Write-Log "exit 0 - Report Installed" 201 | exit 0 202 | # exit 0 - report installed 203 | } 204 | elseif ($AcceptNewerVersion -eq $true -and $InstalledVersion -ge $TargetVersion) { 205 | Write-Log "exit 0 - Report Installed" 206 | exit 0 207 | # exit 0 - report installed 208 | } 209 | else { 210 | Write-Log "exit 1 - Report Not Installed" 211 | exit 1 212 | # exit 1 - report not installed 213 | } 214 | -------------------------------------------------------------------------------- /WinGet-WrapperImportFromCSV.csv: -------------------------------------------------------------------------------- 1 | PackageID,Context,AcceptNewerVersion,UpdateOnly,Version,StopProcessInstall,StopProcessUninstall,PreScriptInstall,PostScriptInstall,PreScriptUninstall,PostScriptUninstall,CustomArgumentListInstall,CustomArgumentListUninstall,InstallIntent,Notification,GroupID 2 | VideoLAN.VLC,Machine,1,1,,,,,,,,,,,, -------------------------------------------------------------------------------- /WinGet-WrapperImportFromCSV.ps1: -------------------------------------------------------------------------------- 1 | # Soren Lundt - 12-09-2023 2 | # URL: https://github.com/SorenLundt/WinGet-Wrapper 3 | # License: https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/main/LICENSE.txt 4 | # 5 | # Imports packages from WinGet to InTune (incuding available WinGet package metadata) 6 | # Package content is stored under Packages\Package.ID-Context-UpdateOnly-UserName-yyyy-mm-dd-hhssmm 7 | # Logs file under Logs\WinGet_WrapperImportFromCSV_yyyy-MM-dd_HH-mm-ss.log 8 | # 9 | # Usage Example: .\WinGet-WrapperImportFromCSV.ps1 -TenantID company.onmicrosoft.com -csvFile WinGet-WrapperImportFromCSV.csv -SkipConfirmation 10 | # 11 | # Parameters: 12 | # csvFile = csvFile to import from (default: WinGet-WrapperImportFromCSV.csv) 13 | # TenantID = TenantID to connect to MSGraph/InTune 14 | # LogFile = Manually define logfile path. If not defined, default will be used 15 | # ScriptRoot = Do not set. Define script root path. Only used when running import job from WinGet-WrapperImportGUI 16 | # SkipConfirmation = Skips confirmation for each package 17 | # SkipModuleCheck = Do not install or update required modules. 18 | # 19 | # 20 | # csvFile columns: 21 | # PackageID,Context,AcceptNewerVersion,UpdateOnly,TargetVersion,StopProcessInstall,StopProcessUninstall,PreScriptInstall,PostScriptInstall,PreScriptUninstall,PostScriptUninstall,CustomArgumentListInstall,CustomArgumentListUninstall,InstallIntent,Notification,GroupID 22 | # 23 | # Requirements: 24 | # Requires Script files and IntuneWinAppUtil.exe to be present in script directory 25 | # 26 | # Version History 27 | # Version 1.0 - 12-09-2023 SorenLundt - Initial Version 28 | # Version 1.1 - 14-09-2023 SorenLundt - Replaced ' with [char]34 (Quotation mark) InTune does not handle ' well 29 | # Version 1.2 - 20-09-2023 SorenLundt - Added possiblity to deploy application once imported. Set via CSV file (InstallIntent, Notification, GroupID) 30 | # Version 1.3 - 20-09-2023 SorenLundt - If -SkipConfirmation set will skip the entire WinGet package output section 31 | # Version 1.4 - 27-09-2023 SorenLundt - Added -OverWrite which will delete apps with the same display name 32 | # Version 1.5 - 27-09-2023 SorenLundt - Remove -OverWrite feature - Requires more work.. Some bugs 33 | # Version 1.6 - 24-10-2023 SorenLundt - When importing packages with UpdateOnly=1 will now use "winget update" instead of "winget install" 34 | # Version 1.7 - 13-11-2023 SorenLundt - Minor script comment and code mismatch for replacing AcceptNeverVersion with $False (was $True) Github issue #7 35 | # Version 1.8 - 13-11-2023 SorenLundt - Removed check if package already exists in InTune. Not reliable. Needs work. Improved required PS modules check/installation 36 | # Version 1.9 - 14-11-2023 SorenLundt - Fixed issue where $True was not being replace by $False for $Row.AcceptNewerVersion value - Github issue #7 37 | # Version 2.0 - 28-11-2023 SorenLundt - Changed various file paths to be able to use script from GUI + added logging 38 | # Version 2.1 - 12-02-2024 SorenLundt - Various improvements/changes to support usage from WinGet-WrapperImportGUI (-SkipModuleCheck -Scriptroot) 39 | # Version 2.2 - 19-02-2023 SorenLundt - Added --accept-source-agreements to winget show commands, to avoid prompt - Github issue #12 40 | 41 | #Parameters 42 | Param ( 43 | #CSV File to import from (default: WinGet-WrapperImportFromCSV.csv) 44 | [Parameter()] 45 | [string]$csvFile = "$PSScriptRoot\WinGet-WrapperImportFromCSV.csv", 46 | 47 | #ClientID to connect to MSGraph/InTune with Connect-MSIntuneGraph 48 | [Parameter(Mandatory = $False)] 49 | [string]$ClientID = "14d82eec-204b-4c2f-b7e8-296a70dab67e", 50 | 51 | #TenantID to connect to MSGraph/InTune 52 | [Parameter(Mandatory=$True)] 53 | [string]$TenantID, 54 | 55 | #LogFile (Manually define logfile path. If not defined, default will be used) 56 | [string]$LogFile, 57 | 58 | #ScriptRoot (Do not set. Define script root path. Only used when running import job from WinGet-WrapperImportGUI) 59 | [string]$ScriptRoot, 60 | 61 | #Skips confirmation for each package before import 62 | [Switch]$SkipConfirmation = $false, 63 | 64 | #Skips Module check 65 | [Switch]$SkipModuleCheck = $false 66 | ) 67 | 68 | #Timestamp 69 | $TimeStamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" 70 | 71 | # Default Log File 72 | if (-not $LogFile) { 73 | $LogFolder = Join-Path -Path $PSScriptRoot -ChildPath "Logs" 74 | 75 | # Create logs folder if it doesn't exist 76 | if (-not (Test-Path -Path $LogFolder)) { 77 | New-Item -Path $LogFolder -ItemType Directory | Out-Null 78 | } 79 | 80 | $LogFile = Join-Path -Path $LogFolder -ChildPath "WinGet_WrapperImportFromCSV_$TimeStamp.log" 81 | } 82 | 83 | function Write-Log { 84 | param ( 85 | [string]$Message, 86 | [string]$LogFile = "$LogFile" 87 | ) 88 | 89 | $LogMsgTimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" 90 | $LogEntry = "[$LogMsgTimeStamp] $Message" 91 | 92 | # Output to the console 93 | Write-Host $LogEntry 94 | 95 | # Append to the log file 96 | $LogEntry | Out-File -Append -FilePath $LogFile 97 | } 98 | Write-Log "Log File: $LogFile" 99 | 100 | Write-log "Parameters: csvFile: $csvFile, TenantID: $TenantID, SkipConfirmation: $SkipConfirmation, LogFile: $LogFile, SkipModuleCheck: $SkipModuleCheck, scriptRoot: $scriptRoot" 101 | 102 | # Install and load required modules 103 | # https://github.com/MSEndpointMgr/IntuneWin32App 104 | if (-not $SkipModuleCheck){ 105 | $intuneWin32AppModule = "IntuneWin32App" 106 | $microsoftGraphIntuneModule = "Microsoft.Graph.Intune" 107 | 108 | # Check if update is required for IntuneWin32App module 109 | $moduleInstalled = Get-InstalledModule -Name $intuneWin32AppModule -ErrorAction SilentlyContinue 110 | 111 | if (-not $moduleInstalled) { 112 | Install-Module -Name $intuneWin32AppModule -Force 113 | } else { 114 | $latestVersion = (Find-Module -Name $intuneWin32AppModule).Version 115 | if ($moduleInstalled.Version -lt $latestVersion) { 116 | Update-Module -Name $intuneWin32AppModule -Force 117 | } else { 118 | Write-Host "Module $intuneWin32AppModule is already up-to-date." 119 | } 120 | } 121 | 122 | # Check if update is required for Microsoft.Graph.Intune module 123 | $moduleInstalled = Get-InstalledModule -Name $microsoftGraphIntuneModule -ErrorAction SilentlyContinue 124 | 125 | if (-not $moduleInstalled) { 126 | Install-Module -Name $microsoftGraphIntuneModule -Force 127 | } else { 128 | $latestVersion = (Find-Module -Name $microsoftGraphIntuneModule).Version 129 | if ($moduleInstalled.Version -lt $latestVersion) { 130 | Update-Module -Name $microsoftGraphIntuneModule -Force 131 | } else { 132 | Write-Host "Module $microsoftGraphIntuneModule is already up-to-date." 133 | } 134 | } 135 | } 136 | #Import modules 137 | Import-Module -Name "IntuneWin32App" 138 | Import-Module -Name "Microsoft.Graph.Intune" 139 | 140 | # Welcome greeting 141 | Write-Log " " 142 | Write-Log " " 143 | Write-Log "-----------------------------" 144 | Write-Log "---- WinGet-WrapperCreate----" 145 | Write-Log "-----------------------------" 146 | Write-Log " " 147 | Write-Log " " 148 | Write-Log "https://github.com/SorenLundt/WinGet-Wrapper" 149 | Write-Log " GNU General Public License v3" 150 | 151 | # Test CSV path 152 | if (Test-Path -Path "$csvFile" -PathType Leaf) { 153 | Write-Log "File: $csvFile" 154 | } else { 155 | Write-Log "File not found: $csvFile" -ForegroundColor "Red" 156 | return 157 | } 158 | 159 | # Import the CSV file with custom headers 160 | $data = Import-Csv -Path "$csvFile" -Header "PackageID", "Context", "AcceptNewerVersion", "UpdateOnly", "TargetVersion", "StopProcessInstall", "StopProcessUninstall", "PreScriptInstall", "PostScriptInstall", "PreScriptUninstall", "PostScriptUninstall", "CustomArgumentListInstall", "CustomArgumentListUninstall", "InstallIntent", "Notification", "GroupID" | Select-Object -Skip 1 161 | 162 | # Convert "AcceptNewerVersion" and "UpdateOnly" columns to Boolean values 163 | $data = $data | ForEach-Object { 164 | $_.AcceptNewerVersion = [bool]($_.AcceptNewerVersion -as [int]) 165 | $_.UpdateOnly = [bool]($_.UpdateOnly -as [int]) 166 | $_ 167 | } 168 | Write-Log "-- IMPORT LIST --" 169 | foreach ($row in $data){ 170 | Write-Log "IMPORT PackageID:$($row.PackageID) - Context:$($row.Context) - UpdateOnly:$($row.UpdateOnly) - TargetVersion:$($row.TargetVersion)" -ForegroundColor Gray 171 | } 172 | Write-Log "" 173 | 174 | Write-Log "-- DEPLOY LIST --" 175 | foreach ($row in $data){ 176 | if ($null = $row.GroupID -or $row.GroupID -ne "") 177 | { 178 | Write-Log "DEPLOY PackageID:$($row.PackageID) GroupID:$($row.GroupID) InstallIntent:$($row.InstallIntent) Notification:$($row.Notification)" -ForegroundColor Gray 179 | } 180 | } 181 | 182 | #Connect to Intune 183 | #if (-not $SkipInTuneConnection){ 184 | try{ 185 | Connect-MSIntuneGraph -TenantID "$TenantID" -ClientID $ClientID -Interactive 186 | } 187 | catch { 188 | Write-Log "ERROR: Connect-MSIntuneGraph Failed. Exiting" -ForegroundColor "Red" 189 | break 190 | } 191 | #} 192 | 193 | 194 | #Import each application to InTune 195 | foreach ($row in $data) { 196 | & { 197 | try{ 198 | #Write-Log "--- Package Details ---" 199 | #Write-Log "PackageID: $($row.PackageID)" 200 | #Write-Log "Context: $($row.Context)" 201 | #Write-Log "AcceptNewerVersion: $($row.AcceptNewerVersion)" 202 | #Write-Log "UpdateOnly: $($row.UpdateOnly)" 203 | #Write-Log "TargetVersion: $($row.TargetVersion)" 204 | #Write-Log "StopProcessInstall: $($row.StopProcessInstall)" 205 | #Write-Log "StopProcessUninstall: $($row.StopProcessUninstall)" 206 | #Write-Log "PreScriptInstall: $($row.PreScriptInstall)" 207 | #Write-Log "PostScriptInstall: $($row.PostScriptInstall)" 208 | #Write-Log "PreScriptUninstall: $($row.PreScriptUninstall)" 209 | #Write-Log "PostScriptUninstall: $($row.PostScriptUninstall)" 210 | #Write-Log "CustomArgumentListInstall: $($row.CustomArgumentListInstall)" 211 | #Write-Log "CustomArgumentListInstall: $($row.CustomArgumentListUninstall)" 212 | 213 | #TimeStamp 214 | $Timestamp = (Get-Date).ToString("yyyyMMddHHmmss") 215 | 216 | #Get User 217 | $currentUser = $env:USERNAME 218 | 219 | Write-Log "--- Validation Start ---" 220 | Write-Log "Validating Package $($row.PackageID)" 221 | #Check context is valid 222 | if ($row.Context -notin @("Machine", "machine", "User", "user")) { 223 | Write-Log "Invalid context setting $($row.Context) for package $($row.PackageID) found in CSV. Please review the CSV. Exiting.." -ForegroundColor "Red" 224 | break 225 | } 226 | 227 | #Check AcceptNewerVersion is true or false 228 | if ($row.AcceptNewerVersion -ne $True -and $row.AcceptNewerVersion -ne $False) 229 | { 230 | Write-Log "Invalid AcceptNewerVersion setting $($row.AcceptNewerVersion) for package $($row.PackageID) found in CSV. Please review the CSV. Exiting.." -ForegroundColor "Red" 231 | break 232 | } 233 | 234 | #Check InstallIntent is valid 235 | if ($null -ne $row.InstallIntent -and $row.InstallIntent -ne "") { 236 | if ($row.InstallIntent -notcontains "Required" -and $row.InstallIntent -notcontains "required" -and $row.InstallIntent -notcontains "Available" -and $row.InstallIntent -notcontains "available") 237 | { 238 | Write-Log "Invalid InstallIntent setting $($row.InstallIntent) for package $($row.PackageID) found in CSV. Please review CSV (Use Available or Required) Exiting.." -ForegroundColor "Red" 239 | break 240 | } 241 | } 242 | 243 | #Check Notification is valid 244 | if ($null -ne $row.Notification -and $row.Notification -ne "") { 245 | $validNotificationValues = "showAll", "showReboot", "hideAll" 246 | if ($validNotificationValues -notcontains $row.Notification.ToLower()) { 247 | Write-Log "Invalid Notification setting $($row.Notification) for package $($row.PackageID) found in CSV. Please review CSV (Use showAll, showReboot, or hideAll) Exiting.." -ForegroundColor "Red" 248 | break 249 | } 250 | } 251 | 252 | #Check GroupID is set if InstallIntent is specified 253 | if ($null -ne $row.InstallIntent -and $row.InstallIntent -ne "") { 254 | if ($row.GroupID -eq $null -or $row.GroupID -eq "") { 255 | Write-Log "Invalid GroupID setting $($row.GroupID) for package $($row.PackageID) found in CSV. Please review CSV. If InstallIntent is set, GroupID must be set too!" 256 | break 257 | } 258 | } 259 | 260 | #Check UpdateOnly is true or false 261 | Write-Log "Checking UpdateOnly Value for $($row.PackageID)" 262 | if ($row.UpdateOnly -ne $True -and $row.UpdateOnly -ne $False) 263 | { 264 | Write-Log "Invalid UpdateOnly setting $($row.UpdateOnly) for package $($row.PackageID) found in CSV. Please review the CSV. Exiting.." -ForegroundColor "Red" 265 | break 266 | } 267 | 268 | #Check StopProcessInstall and StopProcessUninstall does not contain "exe" (inform should not contain .exe) 269 | Write-Log "Checking StopProcessInstall Value for $($row.PackageID)" 270 | if ($row.StopProcessInstall -contains ".") { 271 | Write-Log "Invalid StopProcessInstall setting $($row.StopProcessInstall) for package $($row.PackageID) found in CSV. Please review the CSV. Exiting.." -ForegroundColor "Red" 272 | break 273 | } 274 | Write-Log "Checking StopProcessUninstall Value for $($row.PackageID)" 275 | if ($row.StopProcessUninstall -contains ".") { 276 | Write-Log "Invalid StopProcessUninstall setting $($row.StopProcessUninstall) for package $($row.PackageID) found in CSV. Please review the CSV. Exiting.." -ForegroundColor "Red" 277 | break 278 | } 279 | 280 | #Check PreScriptInstall, PostScriptInstall, PreScriptUninstall, PostScriptUninstall contains .ps1 (inform must be .ps1) 281 | <# 282 | if ( 283 | ($null -ne $row.PreScriptInstall -and -not [string]::IsNullOrEmpty($row.PreScriptInstall)) -or 284 | ($null -ne $row.PostScriptInstall -and -not [string]::IsNullOrEmpty($row.PostScriptInstall)) -or 285 | ($null -ne $row.PreScriptUninstall -and -not [string]::IsNullOrEmpty($row.PreScriptUninstall)) -or 286 | ($null -ne $row.PostScriptUninstall -and -not [string]::IsNullOrEmpty($row.PostScriptUninstall)) 287 | ) { 288 | Write-Log "Checking Pre-Script and Post-Script Values for $($row.PackageID)" 289 | $row.PreScriptInstall 290 | $row.PostScriptInstall 291 | $row.PreScriptUninstall 292 | $row.PostScriptUninstall 293 | if ($row.PreScriptInstall -notlike "*.ps1" -or $row.PostScriptInstall -notlike "*.ps1" -or $row.PreScriptUninstall -notlike "*.ps1" -or $row.PostScriptUninstall -notlike "*.ps1" ) { 294 | Write-Log "Invalid post or pre-script for package $($row.PackageID) found in CSV. Check that the value contains: .ps1 - Please review the CSV. Exiting.." -ForegroundColor "Red" 295 | break 296 | } 297 | } 298 | #> 299 | 300 | #Print CustomArgumentListInstall if set and wait confirm 301 | Write-Log "Checking CustomArgumentListInstall Value for $($row.PackageID)" 302 | if ($row.CustomArgumentListInstall -ne "" -or $null) 303 | { 304 | Write-Log "-- CustomArgumentListInstall --" 305 | Write-Log "$($row.CustomArgumentListInstall)" 306 | if (!$SkipConfirmation) { 307 | $confirmation = Read-Host "Please confirm CustomArgumentListInstall ($PackageID)? (Y/N)" 308 | 309 | if ($confirmation -eq "Y" -or $confirmation -eq "y") { 310 | Write-Log "Confirmed" 311 | } else { 312 | Write-Log "CustomArgumentListInstall not confirmed. Exiting.." 313 | return 314 | } 315 | } 316 | } 317 | 318 | #Print CustomArgumentListUninstall if set and wait confirm 319 | Write-Log "Checking CustomArgumentListUninstall Value for $($row.PackageID)" 320 | if ($row.CustomArgumentListUninstall -ne "" -or $null) 321 | { 322 | Write-Log "-- CustomArgumentListUninstall --" 323 | Write-Log "$($row.CustomArgumentListUninstall)" 324 | if (!$SkipConfirmation) { 325 | $confirmation = Read-Host "Please confirm CustomArgumentListUninstall ($PackageID)? (Y/N)" 326 | 327 | if ($confirmation -eq "Y" -or $confirmation -eq "y") { 328 | Write-Log "Confirmed" 329 | } else { 330 | Write-Log "CustomArgumentListUninstall not confirmed. Exiting.." 331 | return 332 | } 333 | } 334 | } 335 | 336 | Write-Log "Finished Validation for $($row.PackageID)" 337 | Write-Log "--- Validation End ---" 338 | Write-Log "" 339 | 340 | #Print Package details and wait for confirmation. If package not found break. 341 | $PackageIDOutLines = @(winget show --exact --id $($row.PackageID) --scope $($row.Context) --accept-source-agreements) 342 | #Check if targetversion specified 343 | if ($null -ne $row.TargetVersion -and $row.TargetVersion -ne "") 344 | { 345 | $PackageIDOutLines = @(winget show --exact --id $($row.PackageID) --scope $($row.Context) --version $($row.TargetVersion) --accept-source-agreements) 346 | } 347 | $PackageIDout = $PackageIDOutLines -join "`r`n" 348 | 349 | if ($PackageIDOutLines -notcontains "No package found matching input criteria.") { 350 | if ($PackageIDOutLines -notcontains " No applicable installer found; see logs for more details.") { 351 | if (!$SkipConfirmation) { 352 | Write-Log "--- WINGET PACKAGE INFORMATION ---" 353 | Write-Log $PackageIDOut 354 | Write-Log "--------------------------" 355 | $confirmation = Read-Host "Confirm the package details above (Y/N)" 356 | if ($confirmation -eq "N" -or $confirmation -eq "N") { 357 | break 358 | } 359 | } 360 | } else { 361 | # Second condition not met 362 | Write-Log "Applicable installer not found for $($row.Context) context" -ForegroundColor "Red" 363 | $imported = $False 364 | $row | Add-Member -MemberType NoteProperty -Name "Imported" -Value $imported #Write imported status to $row 365 | $errortext = "Applicable installer not found for $($row.Context) context" 366 | $row | Add-Member -MemberType NoteProperty -Name "ErrorText" -Value $errortext #Write errortext to $row 367 | continue 368 | } 369 | } else { 370 | Write-Log "Package $($row.PackageID) not found using winget" -ForegroundColor "Red" 371 | return 372 | } 373 | 374 | 375 | #Scrape Winget package details to use in InTune from $PackageIDOut 376 | #Scrape "Found " Scrape all line from after this 377 | #Scrape "Description" Regex.. Find "Description: " Scrape all line from after this 378 | 379 | #Clear variables 380 | $variables = "PackageName", "Version", "Publisher", "PublisherURL", "PublisherSupportURL", "Author", "Description", "Homepage", "License", "LicenseURL", "Copyright", "CopyrightURL", "InstallerType", "InstallerLocale", "InstallerURL", "InstallerSHA256" 381 | Remove-Variable -Name $variables -ErrorAction SilentlyContinue 382 | 383 | # Use regular expressions to extract details 384 | $PackageName = $PackageIDOut | Select-String -Pattern "Found (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 385 | $PackageName = $PackageName -replace "\[", "(" -replace "\]", ")" #Clean Packagename replace [] with () 386 | $Version = $PackageIDOut | Select-String -Pattern "Version: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 387 | $Publisher = $PackageIDOut | Select-String -Pattern "Publisher: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 388 | $PublisherURL = $PackageIDOut | Select-String -Pattern "Publisher Url: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 389 | $PublisherSupportURL = $PackageIDOut | Select-String -Pattern "Publisher Support Url: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 390 | $Author = $PackageIDOut | Select-String -Pattern "Author: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 391 | $Description = $PackageIDOut | Select-String -Pattern "Description: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 392 | $Homepage = $PackageIDOut | Select-String -Pattern "Homepage: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 393 | $License = $PackageIDOut | Select-String -Pattern "License: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 394 | $LicenseURL = $PackageIDOut | Select-String -Pattern "License Url: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 395 | $Copyright = $PackageIDOut | Select-String -Pattern "Copyright: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 396 | $CopyrightURL = $PackageIDOut | Select-String -Pattern "Copyright Url: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 397 | 398 | # Extract Installer details 399 | $InstallerType = $PackageIDOut | Select-String -Pattern "Installer Type: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 400 | $InstallerLocale = $PackageIDOut | Select-String -Pattern "Installer Locale: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 401 | $InstallerURL = $PackageIDOut | Select-String -Pattern "Installer Url: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 402 | $InstallerSHA256 = $PackageIDOut | Select-String -Pattern "Installer SHA256: (.+)" | ForEach-Object { $_.Matches.Groups[1].Value } 403 | 404 | # Loop through the variable names and assign "None" if empty or null (Avoid script issues) 405 | foreach ($variable in $variables) { 406 | if ($null -eq (Get-Variable -Name $variable -ValueOnly)) { 407 | Set-Variable -Name $variable -Value "None" 408 | } 409 | } 410 | 411 | # Display the extracted variables 412 | Write-Log "" 413 | Write-Log "--- WinGet Scraped Metadata $($row.PackageID) ---" 414 | Write-Log "PackageName: $PackageName" 415 | Write-Log "Version: $Version" 416 | Write-Log "Publisher: $Publisher" 417 | Write-Log "PublisherURL: $PublisherURL" 418 | Write-Log "PublisherSupportURL: $PublisherSupportURL" 419 | Write-Log "Author: $Author" 420 | Write-Log "Description: $Description" 421 | Write-Log "Homepage: $Homepage" 422 | Write-Log "License: $License" 423 | Write-Log "LicenseURL: $LicenseURL" 424 | Write-Log "Copyright: $Copyright" 425 | Write-Log "CopyrightURL: $CopyrightURL" 426 | Write-Log "InstallerType: $InstallerType" 427 | Write-Log "InstallerLocale: $InstallerLocale" 428 | Write-Log "InstallerURL: $InstallerURL" 429 | Write-Log "InstallerSHA256: $InstallerSHA256" 430 | Write-Log "" 431 | Write-Log "--------------------------" 432 | 433 | # Build package details to prepare InTune import 434 | $PackageName += " ($($row.Context))" 435 | if ($Row.TargetVersion -ne $null){ 436 | $PackageName += " $($row.TargetVersion)" 437 | } 438 | 439 | $PackageName += " (WinGet)" 440 | 441 | if ($Row.UpdateOnly -eq $true){ 442 | $PackageName = "Update for " + $PackageName 443 | } 444 | 445 | #Clear ArgumentList and CommandLine parameters. 446 | Remove-Variable -Name ArgumentListInstall, ArgumentListUninstall, InstallCommandLine, UninstallCommandLine -ErrorAction SilentlyContinue 447 | 448 | #Build ArgumentListInstall (if no custom argumentlist set) 449 | if ([string]::IsNullOrEmpty($row.CustomArgumentListInstall)) { 450 | $ArgumentListInstall = "install --exact --id $($row.PackageID) --silent --accept-package-agreements --accept-source-agreements --scope $($row.Context)" 451 | if ($Row.TargetVersion -ne $null -and $Row.TargetVersion -ne "") { 452 | $ArgumentListInstall += " --version $($Row.TargetVersion)" 453 | } 454 | } 455 | else { 456 | $ArgumentListInstall = $row.CustomArgumentListInstall 457 | } 458 | #Replace first 7 characters of ArgumentListInstall with "update" if package is UpdateOnly 459 | if ($Row.UpdateOnly -eq $true) 460 | { 461 | $ArgumentListInstall = "update" + $ArgumentListInstall.Substring(7) 462 | } 463 | 464 | #Build ArgumentListUninstall (if no custom argumentlist set) 465 | if ([string]::IsNullOrEmpty($row.CustomArgumentListUninstall)) { 466 | $ArgumentListUninstall = "uninstall --exact --id $($row.PackageID) --silent --accept-source-agreements --scope $($row.Context)" 467 | if ($Row.TargetVersion -ne $null -and $Row.TargetVersion -ne "") { 468 | $ArgumentListUninstall += " --version $($Row.TargetVersion)" 469 | } 470 | } 471 | else { 472 | $ArgumentListUninstall = $row.CustomArgumentListUninstall 473 | } 474 | 475 | 476 | # Build install commandline 477 | $InstallCommandLine = "Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName $($row.PackageID) -ArgumentList "+[char]34+"$ArgumentListInstall"+[char]34 478 | if ($row.StopProcessInstall -ne $null -and $row.StopProcessInstall -ne ""){ 479 | $InstallCommandLine += " -StopProcess '$($row.StopProcessInstall)'" 480 | } 481 | if ($row.PreScriptInstall -ne $null -and $row.PreScriptInstall -ne ""){ 482 | $InstallCommandLine += " -Prescript '$($row.PreScriptInstall)'" 483 | } 484 | 485 | if ($row.PostScriptInstall -ne $null -and $row.PostScriptInstall -ne "") { 486 | $InstallCommandLine += " -Postscript '$($row.PostScriptInstall)'" 487 | } 488 | 489 | # Build uninstall commandline 490 | $UninstallCommandLine = "Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName $($row.PackageID) -ArgumentList "+[char]34+"$ArgumentListUninstall"+[char]34 491 | if ($row.StopProcessUninstall -ne $null -and $row.StopProcessUninstall -ne ""){ 492 | $UninstallCommandLine += " -StopProcess '$($row.StopProcessUninstall)'" 493 | } 494 | 495 | if ($row.PreScriptUninstall -ne $null -and $row.PreScriptUninstall -ne "") { 496 | $InstallCommandLine += " -PreUninstall '$($row.PreScriptUninstall)'" 497 | } 498 | 499 | if ($row.PostScriptUninstall -ne $null -and $row.PostScriptUninstall -ne "") { 500 | $InstallCommandLine += " -PostUninstall '$($row.PostScriptUninstall)'" 501 | } 502 | 503 | Write-Log " " 504 | Write-Log "--InstallCommandLine--" 505 | Write-Log "$InstallCommandLine" 506 | Write-Log " " 507 | Write-Log "--UninstallCommandLine--" 508 | Write-Log "$UninstallCommandLine" 509 | Write-Log " " 510 | 511 | #Make folder to store script files 512 | 513 | #Find script root - set $currentDirectory 514 | if ($scriptRoot){ 515 | $currentDirectory = $scriptRoot } 516 | else { 517 | $currentDirectory = $PSScriptRoot} 518 | 519 | write-log "currentDirectory: $currentDirectory" 520 | write-log "scriptRoot: $scriptRoot" 521 | write-log "PSScriptRoot: $PSScriptRoot" 522 | write-log "csvFile: $csvFile" 523 | write-log "LogFile: $LogFile" 524 | write-log "TenantID: $TenantID" 525 | write-log "SkipConfirmation: $SkipConfirmation" 526 | write-log "SkipInTuneConnection: $SkipInTuneConnection" 527 | write-log "SkipModuleCheck: $SkipModuleCheck" 528 | # Log the retrieval of variables using Get-Variable 529 | $variables = Get-Variable 530 | foreach ($variable in $variables) { 531 | Write-Output "Retrieving variable: $($variable.Name) = $($variable.Value)" 532 | } 533 | 534 | # Generate foldername 535 | $folderName = "$($Row.PackageID)" 536 | $folderName += "-$($Row.Context)" 537 | 538 | if ($Row.UpdateOnly -eq $True) { 539 | $folderName += "-UpdateOnly" 540 | } 541 | 542 | if ($Row.TargetVersion -ne $null -and $Row.TargetVersion -ne "") { 543 | $folderName += "-V$($Row.TargetVersion)" 544 | } 545 | 546 | $folderName += "-$currentUser-$Timestamp" 547 | 548 | # Combine the current directory and "packages" to create the full "Packages" directory path 549 | $packagesDirectory = Join-Path -Path $currentDirectory -ChildPath "Packages" 550 | 551 | # Check if the "packages" directory exists, and if not, create it 552 | if (-Not (Test-Path -Path $packagesDirectory)) { 553 | New-Item -Path $packagesDirectory -ItemType Directory | Out-Null 554 | } 555 | 556 | # Combine the "Packages" directory path with the folder name to create the full path 557 | $PackageFolderPath = Join-Path -Path $packagesDirectory -ChildPath $folderName 558 | 559 | # Create the subfolder with the desired name 560 | New-Item -Path $PackageFolderPath -ItemType Directory | Out-Null 561 | 562 | Write-Log "Local Package Data Location: $PackageFolderPath" 563 | 564 | #Build DetectionScript 565 | $WingetDetectionScriptSource = "$currentDirectory\WinGet-WrapperDetection.ps1" 566 | $WingetDetectionScriptDestination = "$PackageFolderPath\WinGet-WrapperDetection-$($Row.PackageID).ps1" 567 | 568 | # Copy the source script to the destination 569 | Copy-Item -Path $WingetDetectionScriptSource -Destination $WingetDetectionScriptDestination 570 | 571 | # Read the destination script 572 | $scriptContent = Get-Content -Path $WingetDetectionScriptDestination 573 | 574 | # Identify the start and end of the # Settings section 575 | $startPattern = "# Settings" 576 | $endPattern = "# EndSettings" 577 | 578 | # Join the script content into a single string 579 | $scriptText = [string]::Join([Environment]::NewLine, $scriptContent) 580 | 581 | # Check if the # Settings section is present 582 | if ($scriptText -match "(?s)$startPattern.*?$endPattern") { 583 | $settingsSection = $Matches[0] # Extract the # Settings section 584 | 585 | # If $Row.AcceptNewerVersion is $True, replace "$True" with "$True" 586 | if ($Row.AcceptNewerVersion -eq $True) { 587 | $settingsSection = $settingsSection -replace '"\$True"','$True' 588 | } 589 | # If $Row.AcceptNewerVersion is $False, replace "$True" with "$False" 590 | elseif ($Row.AcceptNewerVersion -eq $False) { 591 | $settingsSection = $settingsSection -replace '"\$True"','$False' 592 | } 593 | 594 | # Replace "Exact WinGet Package ID" with the actual value of $PackageID within the # Settings section 595 | $settingsSection = $settingsSection -replace "Exact WinGet Package ID", $Row.PackageID 596 | 597 | # If $TargetVersion is not null or not empty, replace "TargetVersion = ''" with "TargetVersion = '$TargetVersion'" within the # Settings section 598 | if ($row.TargetVersion -ne $null -and $row.TargetVersion -ne "") { 599 | $settingsSection = $settingsSection -replace 'TargetVersion = ""', "TargetVersion = ""$($Row.TargetVersion)""" 600 | } 601 | 602 | # Replace the updated # Settings section in the script content 603 | $scriptText = $scriptText -replace "(?s)$startPattern.*?$endPattern", $settingsSection 604 | 605 | # Save the updated script content 606 | Set-Content -Path $WingetDetectionScriptDestination -Value $scriptText 607 | 608 | Write-Log "Detection Script complete. $WingetDetectionScriptDestination" 609 | } else { 610 | Write-Log "The # Settings section was not found in the script." -ForegroundColor "Red" 611 | } 612 | 613 | 614 | #Build RequirementScript 615 | if ($Row.UpdateOnly -eq $True){ 616 | $WingetRequirementScriptSource = "$currentDirectory\Winget-WrapperRequirements.ps1" 617 | $WingetRequirementScriptDestination = "$PackageFolderPath\WinGet-WrapperRequirements-$($Row.PackageID).ps1" 618 | 619 | # Copy the source script to the destination 620 | Copy-Item -Path $WingetRequirementScriptSource -Destination $WingetRequirementScriptDestination 621 | 622 | # Read the destination script 623 | $scriptContent = Get-Content -Path $WingetRequirementScriptDestination 624 | 625 | # Check if "Exact WinGet Package ID" is present in the script content 626 | if ($scriptContent -match "Exact WinGet Package ID") { 627 | # Replace "Exact WinGet Package ID" with the actual value of $PackageID 628 | $scriptContent = $scriptContent -replace "Exact WinGet Package ID", $Row.PackageID 629 | 630 | 631 | # Save the updated script content 632 | Set-Content -Path $WingetRequirementScriptDestination -Value $scriptContent 633 | 634 | Write-Log "Requirement Script complete. $WingetRequirementScriptDestination" 635 | } else { 636 | Write-Log "The text 'Exact WinGet Package ID' was not found in the script." -ForegroundColor "Red" 637 | } 638 | } 639 | 640 | #Build Targetversion to use with intune package 641 | if ($row.TargetVersion -ne $null -and $row.TargetVersion -ne "") { 642 | $VersionInfo = $row.TargetVersion 643 | } 644 | else { 645 | $VersionInfo = "Latest" 646 | } 647 | 648 | #Convert Context 649 | if ($row.Context -in @("Machine", "machine")) { 650 | $ContextConverted = "System" 651 | } 652 | elseif ($row.Context -in @("User", "user")) { 653 | $ContextConverted = "User" 654 | } 655 | 656 | #Build IntuneWin Folder (including pre/postscripts if specified in CSV) 657 | # Create a folder named "InTuneWin" if it doesn't exist 658 | try { 659 | $intuneWinFolderPath = Join-Path -Path $PackageFolderPath -ChildPath "InTuneWin" 660 | if (-not (Test-Path -Path $intuneWinFolderPath -PathType Container)) { 661 | New-Item -Path $intuneWinFolderPath -ItemType Directory | Out-Null 662 | } 663 | # Copy WinGet-Wrapper.ps1 664 | Copy-Item -Path "$currentDirectory\WinGet-Wrapper.ps1" -Destination $intuneWinFolderPath -ErrorAction Stop 665 | 666 | # Copy pre or post script if specified 667 | if ($row.PreScriptInstall -ne $null -and $row.PreScriptInstall -ne "") { 668 | Copy-Item -Path $row.PreScriptInstall -Destination $intuneWinFolderPath -ErrorAction Stop 669 | Write-Log "Copied $($row.PreScriptInstall) to $($intuneWinFolderPath)" 670 | } 671 | if ($row.PostScriptInstall -ne $null -and $row.PostScriptInstall -ne "") { 672 | Copy-Item -Path $row.PostScriptInstall -Destination $intuneWinFolderPath -ErrorAction Stop 673 | Write-Log "Copied $($row.PostScriptInstall) to $($intuneWinFolderPath)" 674 | } 675 | if ($row.PreScriptUninstall -ne $null -and $row.PreScriptUninstall -ne "") { 676 | Copy-Item -Path $row.PreScriptUninstall -Destination $intuneWinFolderPath -ErrorAction Stop 677 | Write-Log "Copied $($row.PreScriptUninstall) to $($intuneWinFolderPath)" 678 | } 679 | if ($row.PostScriptUninstall -ne $null -and $row.PostScriptUninstall -ne "") { 680 | Copy-Item -Path $row.PostScriptUninstall -Destination $intuneWinFolderPath -ErrorAction Stop 681 | Write-Log "Copied $($row.PostScriptUninstall) to $($intuneWinFolderPath)" 682 | }} 683 | catch { 684 | Write-Log "Failed to copy files to build InTuneWin package. Please check pre/post script is found" 685 | return 686 | } 687 | 688 | # Build WinGet-Wrapper.intunewin 689 | Write-Log "Building WinGet-Wrapper.InTuneWin file" 690 | try { 691 | [string]$toolargs = "-c ""$($intuneWinFolderPath)"" -s ""WinGet-Wrapper.ps1"" -o ""$($PackageFolderPath)"" -q" 692 | (Start-Process -FilePath "$currentDirectory\IntuneWinAppUtil.exe" -ArgumentList $toolargs -PassThru:$true -ErrorAction Stop -NoNewWindow).WaitForExit() 693 | 694 | # Check that IntuneWin was created 695 | if (Test-Path -Path "$PackageFolderPath\WinGet-Wrapper.intunewin" -PathType Leaf) { 696 | Write-Log "IntuneWinAppUtil.exe built WinGet-Wrapper.intunewin for $PackageName" 697 | } 698 | else { 699 | Write-Log "IntuneWinAppUtil.exe could not build WinGet-Wrapper.intunewin" 700 | return 701 | } 702 | 703 | } 704 | catch { 705 | Write-Log "Error running IntuneWinAppUtil.exe" 706 | return 707 | } 708 | 709 | #Set WinGet-Wrapper.intunewin path 710 | $WinGetWrapperInTuneWinFilePath = Join-Path -Path $PackageFolderPath -ChildPath 'WinGet-Wrapper.intunewin' 711 | 712 | #Detection 713 | $DetectionRuleScript = New-IntuneWin32AppDetectionRuleScript -ScriptFile $WingetDetectionScriptDestination 714 | 715 | #RequirementRule Base 716 | $RequirementRule = New-IntuneWin32AppRequirementRule -Architecture "All" -MinimumSupportedWindowsRelease "W10_20H2" 717 | 718 | # Build base Add-InTuneWin32App Arguments 719 | $AddInTuneWin32AppArguments = @{ 720 | FilePath = "$WinGetWrapperInTuneWinFilePath" 721 | DisplayName = "$PackageName" 722 | Description = "$Description" 723 | Publisher = "$Publisher" 724 | AppVersion = "$VersionInfo" 725 | Developer = "$Author" 726 | InstallCommandLine = "$InstallCommandLine" 727 | UninstallCommandLine = "$UninstallCommandLine" 728 | InstallExperience = "$ContextConverted" 729 | RestartBehavior = "suppress" 730 | Owner = "$currentUser" 731 | Notes = "Created by $currentUser at $Timestamp using WinGet-WrapperCreateFromCSV (https://github.com/SorenLundt/WinGet-Wrapper)" 732 | DetectionRule = $DetectionRuleScript 733 | RequirementRule = $RequirementRule 734 | } 735 | 736 | # Build AdditionalRequirementRule (if UpdateOnly True) 737 | if ($Row.UpdateOnly -eq $True) { 738 | $AdditionalRequirementRule = New-IntuneWin32AppRequirementRuleScript -ScriptFile $WingetRequirementScriptDestination -ScriptContext "$ContextConverted" -StringComparisonOperator "equal" -StringOutputDataType -StringValue "Installed" 739 | $AddInTuneWin32AppArguments.AdditionalRequirementRule = $AdditionalRequirementRule 740 | } else { 741 | } 742 | 743 | # If overwrite enabled , remove win32app from intune before importing 744 | # Disabled section. Needs more work. 745 | <# 746 | if ($Overwrite -eq $True) { 747 | try{ 748 | Write-Log "Overwrite enabled - Attempting to remove Win32App if it already exists in InTune - $PackageName " 749 | Write-Log "$packagename" 750 | $CheckIntuneAppExists = Get-IntuneWin32App -DisplayName "$PackageName" 751 | Write-Log "627 - $CheckIntuneAppExists" 752 | if ($CheckIntuneAppExists.Count -gt 0) 753 | { 754 | Write-Log "Package found in InTune " 755 | Remove-IntuneWin32App -DisplayName "$PackageName" 756 | [int]$NumberOfTimesChecked = 1 757 | do { 758 | Write-Log "Checking if Win32App was removed before continuing. Checks: $NumberOfTimesChecked" 759 | Write-Log "635 - $CheckIntuneAppExists" 760 | $CheckIntuneAppExists = Get-IntuneWin32App -DisplayName "$PackageName" 761 | Start-Sleep 15 762 | $NumberOfTimesChecked++ 763 | } while ($CheckIntuneAppExists.Count -gt 0) 764 | } 765 | } 766 | catch { 767 | Write-Log "An error occurred: $_.Exception.Message" -ForeGroundColor "Red" 768 | $imported = $False 769 | $row | Add-Member -MemberType NoteProperty -Name "Imported" -Value $imported #Write imported status to $row 770 | $errortext = "Error Remvoving Win32App: $_.Exception.Message" 771 | $row | Add-Member -MemberType NoteProperty -Name "ErrorText" -Value $errortext #Write errortext to $row 772 | continue 773 | } 774 | 775 | } 776 | #> 777 | 778 | # Disabled section. Needs more work. 779 | <# 780 | Write-Log "Checking if application already exists in Intune - $PackageName" 781 | # Get the Intune Win32 apps with the specified display name 782 | $CheckIntuneAppExists = Get-IntuneWin32App -DisplayName "$PackageName" -WarningAction SilentlyContinue 783 | 784 | # Check if any matching applications were found 785 | Write-Log "CheckInTuneAppExists.Count = $($CheckIntuneAppExists.Count)" 786 | if ($CheckIntuneAppExists.Count -gt 0) { 787 | Write-Log "ERROR: Application with the same name already exists in Intune. Could not import - $PackageName" -ForegroundColor "Red" 788 | $imported = $False 789 | $row | Add-Member -MemberType NoteProperty -Name "Imported" -Value $imported #Write imported status to $row 790 | $errortext = "Already exists in InTune" 791 | $row | Add-Member -MemberType NoteProperty -Name "ErrorText" -Value $errortext #Write errortext to $row 792 | continue 793 | } 794 | else { 795 | Write-Log "OK! A similar package was not found in Intune." 796 | } 797 | #> 798 | 799 | #Import application to InTune 800 | try { 801 | Write-Log "Importing application '$PackageName' to InTune" 802 | $AppImport = Add-IntuneWin32App @AddInTuneWin32AppArguments -WarningAction Continue -ErrorAction Continue 803 | $AppID = $AppImport.ID 804 | $row | Add-Member -MemberType NoteProperty -Name "AppID" -Value $AppID #Write AppID to $row 805 | Write-Log "Imported application '$PackageName' to InTune" -ForeGroundColor "Green" 806 | $imported = $True 807 | } 808 | catch { 809 | Write-Log "An error occurred: $($_.Exception.Message)" -ForeGroundColor "Red" 810 | $imported = $False 811 | $row | Add-Member -MemberType NoteProperty -Name "Imported" -Value $imported #Write imported status to $row 812 | $errortext = "Error Importing: $($_.Exception.Message)" 813 | $row | Add-Member -MemberType NoteProperty -Name "ErrorText" -Value $errortext #Write errortext to $row 814 | continue 815 | } 816 | 817 | # Deploy Application if set - Install Intent "Required" 818 | try { 819 | if ($Row.InstallIntent -contains "Required" -and ($null -ne $Row.GroupID -and $Row.GroupID -ne "")) { 820 | Add-IntuneWin32AppAssignmentGroup -Include -ID $Row.AppID -GroupID $Row.GroupID -Intent $row.InstallIntent -Notification $row.Notification -ErrorAction continue 821 | Write-Log "Deployed AppID:$($Row.AppID) to $($Row.GroupID)" -ForeGroundColor "Green" 822 | } 823 | 824 | # Deploy Application if set - Install Intent "Available" 825 | if ($Row.InstallIntent -contains "Available" -and ($null -ne $Row.GroupID -and $Row.GroupID -ne "")) { 826 | Add-IntuneWin32AppAssignmentGroup -Include -ID $Row.AppID -GroupID $Row.GroupID -Intent $row.InstallIntent -Notification $row.Notification -ErrorAction continue 827 | Write-Log "Deployed AppID:$($Row.AppID) to $($Row.GroupID)" -ForeGroundColor "Green" 828 | } 829 | } 830 | catch { 831 | Write-Log "Error deploying $($Row.PackageID) : $_" 832 | } 833 | 834 | #Success 835 | $imported = $True 836 | $row | Add-Member -MemberType NoteProperty -Name "Imported" -Value $imported #Write imported status to $row 837 | 838 | } 839 | catch { 840 | #Failed 841 | $imported = $False 842 | $row | Add-Member -MemberType NoteProperty -Name "Imported" -Value $imported #Write imported status to $row 843 | $errortext = "Unknown Error: $_.Exception.Message" 844 | $row | Add-Member -MemberType NoteProperty -Name "ErrorText" -Value $errortext #Write errortext to $row 845 | 846 | } 847 | 848 | #If more packages to import, wait 15 seconds to avoid throttling. Microsoft Graph throttling ? 849 | # Check if there are more than 2 rows in $data 850 | if ($data.Count -gt 2) { 851 | Write-Log "Waiting 15s before importing next package.. (Throttle)" 852 | Start-Sleep -Seconds 15 853 | } 854 | 855 | } 856 | } 857 | ###### END FOREACH ###### 858 | 859 | #Write Results 860 | Write-Log "---- RESULTS Package Creation ----" 861 | foreach ($row in $data) { 862 | $importedStatus = $row.Imported 863 | $textColor = "Green" # Default to green 864 | $importedtext = "Success" #Default to success 865 | if (-not $importedStatus) { 866 | $textColor = "Red" # Change to red if Imported is False 867 | $importedtext = "Failed" 868 | } 869 | Write-Log "" 870 | $formattedText = "IMPORTED:$ImportedText PackageID:$($row.PackageID) AppID:$($row.AppID) TargetVersion:$($row.TargetVersion) Context:$($row.Context) UpdateOnly: $($row.UpdateOnly) AcceptNewerVersion: $($row.AcceptNewerVersion) ErrorText: $($row.ErrorText)" 871 | Write-Log $formattedText -ForegroundColor $textColor 872 | 873 | # If deployed also show these results 874 | if ($null = $row.GroupID -or $row.GroupID -ne ""){ 875 | if ($importedStatus -eq $True) 876 | { 877 | Write-Log "> DEPLOYED:$($row.PackageID) AppID:$($row.AppID) ----> GroupID:$($row.GroupID) InstallIntent:$($row.InstallIntent) Notification:$($row.Notification)" -ForegroundColor $textColor 878 | } 879 | } 880 | Write-Host "Log File: $LogFile" 881 | } 882 | -------------------------------------------------------------------------------- /WinGet-WrapperImportGUI.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/WinGet-WrapperImportGUI.exe -------------------------------------------------------------------------------- /WinGet-WrapperImportGUI.ps1: -------------------------------------------------------------------------------- 1 | # Soren Lundt - 12-02-2024 2 | # URL: https://github.com/SorenLundt/WinGet-Wrapper 3 | # License: https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/main/LICENSE.txt 4 | # Graphical interface for WinGet-Wrapper Import 5 | # Package content is stored under Packages\Package.ID-Context-UpdateOnly-UserName-yyyy-mm-dd-hhssmm 6 | 7 | # Requirements: 8 | # Requires Script files and IntuneWinAppUtil.exe to be present in script directory 9 | # 10 | # Version History 11 | # Version 1.0 - 12-02-2024 SorenLundt - Initial Version 12 | # Version 1.1 - 21-02-2024 SorenLundt - Fixed issue where only 1 package was imported to InTune (Script assumed there was just one row) 13 | # Version 1.2 - 30-10-2024 SorenLundt - Various improvements (Ability to get details and available versions for packages, loading GUI progressbar, link to repo, unblock script files, bug fixes.) 14 | # Version 1.3 - 31-10-2024 SorenLundt - Added Column Definitions help button, added SKIPMODULECHECK param to skip check if required modules are up-to-date. (testing use) 15 | 16 | #Parameters 17 | Param ( 18 | #Skip module checking (for testing purposes) 19 | [Switch]$SKIPMODULECHECK = $false 20 | ) 21 | 22 | # Greeting 23 | write-host "" 24 | Write-Host "****************************************************" 25 | Write-Host " WinGet-Wrapper)" 26 | Write-Host " https://github.com/SorenLundt/WinGet-Wrapper" 27 | Write-Host "" 28 | Write-Host " GNU General Public License v3" 29 | Write-Host "****************************************************" 30 | write-host " WinGet-WrapperImportGUI Starting up.." 31 | write-host "" 32 | 33 | # Function to show loading progress bar in console. 34 | function Show-ConsoleProgress { 35 | param ( 36 | [string]$Activity = "Loading Winget-Wrapper Import GUI", 37 | [string]$Status = "", 38 | [int]$PercentComplete = 0 39 | ) 40 | Write-Host "$Status - [$PercentComplete%]" 41 | Write-Progress -Activity $Activity -Status $Status -PercentComplete $PercentComplete 42 | } 43 | 44 | # Update ConsoleProgress 45 | Show-ConsoleProgress -PercentComplete 0 -Status "Initializing..." 46 | 47 | # Add required assemblies 48 | Add-Type -AssemblyName System.Windows.Forms 49 | Add-Type -AssemblyName System.Drawing 50 | 51 | # Set the timestamp for log file 52 | $timestamp = Get-Date -Format "yyyyMMddHHmmss" 53 | 54 | #Find Script root path 55 | if (-not $PSScriptRoot) { 56 | $scriptRoot = (Get-Location -PSProvider FileSystem).ProviderPath 57 | } else { 58 | $scriptRoot = $PSScriptRoot 59 | } 60 | 61 | # Create logs folder if it doesn't exist 62 | $LogFolder = Join-Path -Path $scriptRoot -ChildPath "Logs" 63 | # Create logs folder if it doesn't exist 64 | if (-not (Test-Path -Path $LogFolder)) { 65 | New-Item -Path $LogFolder -ItemType Directory | Out-Null 66 | } 67 | 68 | # Install and load required modules 69 | $intuneWin32AppModule = "IntuneWin32App" 70 | $microsoftGraphIntuneModule = "Microsoft.Graph.Intune" 71 | 72 | #DEBUG (Skip ModuleCheck) 73 | #$SKIPMODULECHECK = $true 74 | if (-not $SKIPMODULECHECK) { 75 | 76 | # Check IntuneWin32App module 77 | # Update ConsoleProgress 78 | Show-ConsoleProgress -PercentComplete 10 -Status "Checking and updating $intuneWin32AppModule.." 79 | $moduleInstalled = Get-InstalledModule -Name $intuneWin32AppModule -ErrorAction SilentlyContinue 80 | if (-not $moduleInstalled) { 81 | Install-Module -Name $intuneWin32AppModule -Force 82 | } else { 83 | $latestVersion = (Find-Module -Name $intuneWin32AppModule).Version 84 | if ($moduleInstalled.Version -lt $latestVersion) { 85 | Update-Module -Name $intuneWin32AppModule -Force 86 | } else { 87 | Write-Host "Module $intuneWin32AppModule is already up-to-date." -ForegroundColor Green 88 | } 89 | } 90 | 91 | # Check Microsoft.Graph.Intune module 92 | # Update ConsoleProgress 93 | Show-ConsoleProgress -PercentComplete 40 -Status "Checking and updating $microsoftGraphIntuneModule.." 94 | $moduleInstalled = Get-InstalledModule -Name $microsoftGraphIntuneModule -ErrorAction SilentlyContinue 95 | 96 | if (-not $moduleInstalled) { 97 | Install-Module -Name $microsoftGraphIntuneModule -Force 98 | } else { 99 | $latestVersion = (Find-Module -Name $microsoftGraphIntuneModule).Version 100 | if ($moduleInstalled.Version -lt $latestVersion) { 101 | Update-Module -Name $microsoftGraphIntuneModule -Force 102 | } else { 103 | Write-Host "Module $microsoftGraphIntuneModule is already up-to-date." -ForegroundColor Green 104 | } 105 | } 106 | } 107 | 108 | 109 | #Import modules 110 | Show-ConsoleProgress -PercentComplete 60 -Status "Importing module $intuneWin32AppModule.." 111 | Import-Module -Name "IntuneWin32App" 112 | 113 | Show-ConsoleProgress -PercentComplete 80 -Status "Importing module $microsoftGraphIntuneModule.." 114 | Import-Module -Name "Microsoft.Graph.Intune" 115 | 116 | Show-ConsoleProgress -PercentComplete 90 -Status "Unblocking script files (Unblock-File)" 117 | # Unblock all files in the current directory 118 | $files = Get-ChildItem -Path . -File 119 | foreach ($file in $files) { 120 | try { 121 | Unblock-File -Path $file.FullName 122 | } catch { 123 | Write-Host "Failed to unblock: $($file.FullName) - $_" 124 | } 125 | } 126 | 127 | # Update ConsoleProgress 128 | Show-ConsoleProgress -PercentComplete 80 -Status "Loading functions.." 129 | 130 | #Functions 131 | function Write-ConsoleTextBox { 132 | param ( 133 | [string]$Message, 134 | [switch]$NoTimeStamp 135 | ) 136 | 137 | if (-not $NoTimeStamp) { 138 | $TimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" 139 | $Message = "[$TimeStamp] $Message" 140 | } 141 | 142 | # Output to the console 143 | Write-Host $Message 144 | 145 | # Append to the console textbox 146 | $consoleTextBox.AppendText("$Message`r`n") 147 | } 148 | 149 | 150 | # Function to read log file and update the GUI 151 | function Update-GUIFromLogFile { 152 | param ( 153 | [string]$logFilePath 154 | ) 155 | # Read the log file content 156 | $logContent = Get-Content -Path $logFilePath 157 | 158 | # Assuming Write-ConsoleTextBox adds each line to the GUI's textbox 159 | foreach ($line in $logContent) { 160 | Write-ConsoleTextBox -Message $line -NoTimeStamp 161 | } 162 | } 163 | 164 | # Update ConsoleProgress 165 | Show-ConsoleProgress -PercentComplete 90 -Status "Loading GUI elements.." 166 | 167 | # GUI 168 | # Create form 169 | $form = New-Object System.Windows.Forms.Form 170 | $form.Text = "Winget-Wrapper Import GUI - https://github.com/SorenLundt/WinGet-Wrapper" 171 | $form.Width = 1475 172 | $form.Height = 980 173 | $form.BackColor = [System.Drawing.Color]::WhiteSmoke 174 | $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle 175 | $form.Topmost = $false 176 | $form.MaximizeBox = $False 177 | 178 | # Set the icon for the form 179 | write-host "$scriptRoot" 180 | $iconPath = Join-Path -Path $scriptRoot -ChildPath "Winget-Wrapper.ico" 181 | if (Test-Path $iconPath) { 182 | $icon = New-Object System.Drawing.Icon($iconPath) 183 | $form.Icon = $icon 184 | } else { 185 | Write-Host "Icon file not found at $iconPath" 186 | } 187 | 188 | <# Create a Link to GitHub page 189 | $linkLabelGitHub = New-Object System.Windows.Forms.LinkLabel 190 | $linkLabelGitHub.Text = 'Visit the GitHub Repository' 191 | $linkLabelGitHub.Location = New-Object System.Drawing.Point(1296, 5) # Adjusted position for better layout 192 | $linkLabelGitHub.AutoSize = $true 193 | $linkLabelGitHub.LinkColor = [System.Drawing.Color]::Blue 194 | $linkLabelGitHub.Font = New-Object System.Drawing.Font('Arial', 8, [System.Drawing.FontStyle]::Bold) # Use the same font as the Column Guide 195 | $linkLabelGitHub.BackColor = [System.Drawing.Color]::LightGray # Background color for consistency 196 | $linkLabelGitHub.Padding = New-Object System.Windows.Forms.Padding(1) # Add padding for consistency 197 | $linkLabelGitHub.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle # Add a border to make it stand out 198 | $form.Controls.Add($linkLabelGitHub)#> 199 | 200 | # Create a Link to GitHub page 201 | $linkLabelGitHub = New-Object System.Windows.Forms.LinkLabel 202 | $linkLabelGitHub.Text = 'Visit the GitHub Repository' 203 | $linkLabelGitHub.Location = New-Object System.Drawing.Point(1280, 10) 204 | $linkLabelGitHub.AutoSize = $true 205 | $linkLabelGitHub.LinkColor = [System.Drawing.Color]::Blue 206 | $linkLabelGitHub.Font = New-Object System.Drawing.Font('Arial', 10, [System.Drawing.FontStyle]::Underline) 207 | $form.Controls.Add($linkLabelGitHub) 208 | 209 | # Create a help label to get column definitions 210 | $ColumnHelpLabel = New-Object System.Windows.Forms.Label 211 | $ColumnHelpLabel.Text = 'Show Column Definitions' 212 | $ColumnHelpLabel.Location = New-Object System.Drawing.Point(1310, 40) 213 | $ColumnHelpLabel.AutoSize = $true 214 | #$ColumnHelpLabel.ForeColor = [System.Drawing.Color]::Blue # Set text color to blue 215 | $ColumnHelpLabel.Font = New-Object System.Drawing.Font('Arial', 8, [System.Drawing.FontStyle]::Bold) # Make the text bold 216 | $ColumnHelpLabel.BackColor = [System.Drawing.Color]::LightGray # Background color for contrast 217 | $ColumnHelpLabel.Padding = New-Object System.Windows.Forms.Padding(1) # Add some padding around the text 218 | $form.Controls.Add($ColumnHelpLabel) 219 | 220 | # Add click event to the LinkLabel 221 | $linkLabelGitHub.Add_LinkClicked({ 222 | Start-Process "https://github.com/SorenLundt/WinGet-Wrapper" # Change to your desired URL 223 | }) 224 | 225 | # Click event for Column Help Button 226 | $ColumnHelpLabel.Add_Click({ 227 | GetColumnDefinitions 228 | }) 229 | 230 | # Create TextBox for search string 231 | $searchBox = New-Object System.Windows.Forms.TextBox 232 | $searchBox.Location = New-Object System.Drawing.Point(10, 10) 233 | $searchBox.Width = 400 234 | $form.Controls.Add($searchBox) 235 | $searchBoxtooltip = New-Object System.Windows.Forms.ToolTip 236 | $searchBoxtooltip.SetToolTip($searchBox, 'Enter software name, ex. VLC, 7-zip, etc.') 237 | 238 | # Create Button for search 239 | $searchButton = New-Object System.Windows.Forms.Button 240 | $searchButton.Location = New-Object System.Drawing.Point(420, 8) 241 | $searchButton.Width = 50 242 | $searchButton.Text = "Search" 243 | $form.Controls.Add($searchButton) 244 | 245 | # Create Label to display search error 246 | $searchErrorLabel = New-Object System.Windows.Forms.Label 247 | $searchErrorLabel.Location = New-Object System.Drawing.Point(480, 10) 248 | $searchErrorLabel.Width = 500 249 | #$searchErrorLabel.ForeColor = [System.Drawing.Color]::Tomato 250 | $form.Controls.Add($searchErrorLabel) 251 | 252 | # Create Label for $dataGridView (Results) 253 | $resultsLabel = New-Object System.Windows.Forms.Label 254 | $resultsLabel.Location = New-Object System.Drawing.Point(10, 37) 255 | $resultsLabel.Width = 200 256 | $resultsLabel.Text = "WinGet Packages" 257 | $form.Controls.Add($resultsLabel) 258 | 259 | # Create DataGridView for results 260 | $dataGridView = New-Object System.Windows.Forms.DataGridView 261 | $dataGridView.Location = New-Object System.Drawing.Point(10, 60) 262 | $dataGridView.Width = 600 263 | $dataGridView.Height = 500 264 | $dataGridView.SelectionMode = [System.Windows.Forms.DataGridViewSelectionMode]::FullRowSelect # Only allow full row selection 265 | $form.Controls.Add($dataGridView) 266 | 267 | # Add columns to DataGridView 268 | $dataGridView.Columns.Add("Name", "Name") 269 | $dataGridView.Columns.Add("ID", "ID") 270 | $dataGridView.Columns.Add("Version", "Version") 271 | 272 | # Set initial widths for columns in the DataGridView 273 | $dataGridView.Columns['Name'].Width = 200 # Adjust the width as needed 274 | $dataGridView.Columns['ID'].Width = 150 # Adjust the width as needed 275 | $dataGridView.Columns['Version'].Width = 100 # Adjust the width as needed 276 | 277 | # Create Label for $dataGridView (Selected) 278 | $resultsLabel = New-Object System.Windows.Forms.Label 279 | $resultsLabel.Location = New-Object System.Drawing.Point(650, 37) 280 | $resultsLabel.Width = 200 281 | $resultsLabel.Text = "InTune Import List" 282 | $form.Controls.Add($resultsLabel) 283 | 284 | # Create a second DataGridView 285 | $dataGridViewSelected = New-Object System.Windows.Forms.DataGridView 286 | $dataGridViewSelected.Location = New-Object System.Drawing.Point(650, 60) 287 | $dataGridViewSelected.Width = 800 288 | $dataGridViewSelected.Height = 500 289 | $form.Controls.Add($dataGridViewSelected) 290 | 291 | # Add columns to the second DataGridView 292 | $dataGridViewSelected.Columns.Add("PackageID", "PackageID") 293 | $dataGridViewSelected.Columns.Add("Context", "Context") 294 | $dataGridViewSelected.Columns.Add("AcceptNewerVersion", "AcceptNewerVersion") 295 | $dataGridViewSelected.Columns.Add("UpdateOnly", "UpdateOnly") 296 | $dataGridViewSelected.Columns.Add("TargetVersion", "TargetVersion") 297 | $dataGridViewSelected.Columns.Add("StopProcessInstall", "StopProcessInstall") 298 | $dataGridViewSelected.Columns.Add("StopProcessUninstall", "StopProcessUninstall") 299 | $dataGridViewSelected.Columns.Add("PreScriptInstall", "PreScriptInstall") 300 | $dataGridViewSelected.Columns.Add("PostScriptInstall", "PostScriptInstall") 301 | $dataGridViewSelected.Columns.Add("PreScriptUninstall", "PreScriptUninstall") 302 | $dataGridViewSelected.Columns.Add("PostScriptUninstall", "PostScriptUninstall") 303 | $dataGridViewSelected.Columns.Add("CustomArgumentListInstall", "CustomArgumentListInstall") 304 | $dataGridViewSelected.Columns.Add("CustomArgumentListUninstall", "CustomArgumentListUninstall") 305 | $dataGridViewSelected.Columns.Add("InstallIntent", "InstallIntent") 306 | $dataGridViewSelected.Columns.Add("Notification", "Notification") 307 | $dataGridViewSelected.Columns.Add("GroupID", "GroupID") 308 | 309 | # Set initial widths for columns in the DataGridViewSelected 310 | foreach ($column in $dataGridViewSelected.Columns){ 311 | $column.Width = "80" 312 | } 313 | 314 | # Create Button for exporting CSV from dataGridViewSelected 315 | $exportButton = New-Object System.Windows.Forms.Button 316 | $exportButton.Location = New-Object System.Drawing.Point(760, 565) 317 | $exportButton.Width = 100 318 | $exportButton.Text = "Export CSV" 319 | $form.Controls.Add($exportButton) 320 | 321 | # Create Button for moving selected rows with a right-arrow icon 322 | $moveButton = New-Object System.Windows.Forms.Button 323 | $moveButton.Location = New-Object System.Drawing.Point(618, 280) 324 | $moveButton.Width = 30 325 | $moveButton.Height = 30 326 | $moveButtontooltip = New-Object System.Windows.Forms.ToolTip 327 | $moveButtontooltip.SetToolTip($moveButton, 'Add Selected Package(s) to Import List') 328 | 329 | # Create a Bitmap for the arrow icon 330 | $arrowIcon = New-Object System.Drawing.Bitmap 50, 50 331 | 332 | # Draw a right arrow onto the Bitmap 333 | $arrowGraphics = [System.Drawing.Graphics]::FromImage($arrowIcon) 334 | $arrowBrush = [System.Drawing.Brushes]::Black 335 | $arrowGraphics.FillPolygon($arrowBrush, @( 336 | [System.Drawing.Point]::new(10, 10), 337 | [System.Drawing.Point]::new(30, 25), 338 | [System.Drawing.Point]::new(10, 40) 339 | )) 340 | $arrowGraphics.Dispose() 341 | 342 | # Set the button's appearance and icon 343 | $moveButton.FlatStyle = 'Flat' 344 | $moveButton.FlatAppearance.BorderSize = 0 345 | $moveButton.BackgroundImage = $arrowIcon 346 | $moveButton.BackgroundImageLayout = 'Stretch' 347 | $moveButton.Text = "" 348 | $form.Controls.Add($moveButton) 349 | 350 | # Create Button for deleting selected rows 351 | $deleteButton = New-Object System.Windows.Forms.Button 352 | $deleteButton.Location = New-Object System.Drawing.Point(1350, 565) 353 | $deleteButton.Width = 100 354 | $deleteButton.Text = "Delete Selected" 355 | $form.Controls.Add($deleteButton) 356 | 357 | # Create Button for importing CSV to dataGridViewSelected 358 | $importCSVButton = New-Object System.Windows.Forms.Button 359 | $importCSVButton.Location = New-Object System.Drawing.Point(650, 565) 360 | $importCSVButton.Width = 100 361 | $importCSVButton.Text = "Import CSV" 362 | $form.Controls.Add($importCSVButton) 363 | 364 | # Create a TextBox for console output 365 | $consoleTextBox = New-Object System.Windows.Forms.TextBox 366 | $consoleTextBox.Location = New-Object System.Drawing.Point(10, 650) 367 | $consoleTextBox.Width = 1420 368 | $consoleTextBox.Height = 280 369 | $consoleTextBox.Multiline = $true 370 | $consoleTextBox.ScrollBars = "Vertical" 371 | $form.Controls.Add($consoleTextBox) 372 | 373 | # Create Button for importing data into InTune 374 | $InTuneimportButton = New-Object System.Windows.Forms.Button 375 | $InTuneimportButton.Location = New-Object System.Drawing.Point(650, 615) 376 | $InTuneimportButton.Width = 120 377 | $InTuneimportButton.Text = "Import to InTune" 378 | $IntuneImportButton.Visible = $True 379 | $form.Controls.Add($InTuneimportButton) 380 | 381 | # Create TextBox for Tenant ID 382 | $tenantIDTextBox = New-Object System.Windows.Forms.TextBox 383 | $tenantIDTextBox.Location = New-Object System.Drawing.Point(650, 590) 384 | $tenantIDTextBox.Width = 300 385 | $form.Controls.Add($tenantIDTextBox) 386 | 387 | # Help text for Tenant ID textbox 388 | $tenantIDTextBoxDefaultText = "Enter Tenant ID (e.g., company.onmicrosoft.com)" 389 | $tenantIDTextBox.Text = "$tenantIDTextBoxDefaultText" 390 | $tenantIDTextBox.ForeColor = [System.Drawing.Color]::Gray 391 | 392 | # Create Button for Getting Package Details 393 | $GetPackageDetails = New-Object System.Windows.Forms.Button 394 | $GetPackageDetails.Location = New-Object System.Drawing.Point(10, 565) 395 | $GetPackageDetails.Width = 240 396 | $GetPackageDetails.Text = "Get detailed info for selected package(s)" 397 | $GetPackageDetails.Visible = $True 398 | $form.Controls.Add($GetPackageDetails) 399 | 400 | # Create Button for Getting Package Versions 401 | $GetPackageVersions = New-Object System.Windows.Forms.Button 402 | $GetPackageVersions.Location = New-Object System.Drawing.Point(260, 565) 403 | $GetPackageVersions.Width = 240 404 | $GetPackageVersions.Text = "Get available versions for selected package(s)" 405 | $GetPackageVersions.Visible = $True 406 | $form.Controls.Add($GetPackageVersions) 407 | 408 | # Update ConsoleProgress 409 | Show-ConsoleProgress -PercentComplete 95 -Status "Loading Event handlers.." 410 | 411 | # EVENTS 412 | # Event handler for when the textbox gains focus (Enter event) 413 | $tenantIDTextBox.Add_Enter({ 414 | if ($tenantIDTextBox.Text -eq "$tenantIDTextBoxDefaultText") { 415 | $tenantIDTextBox.Text = "" 416 | $tenantIDTextBox.ForeColor = [System.Drawing.Color]::Black 417 | } 418 | }) 419 | 420 | # Event handler for when the textbox loses focus (Leave event) 421 | $tenantIDTextBox.Add_Leave({ 422 | if ([string]::IsNullOrWhiteSpace($tenantIDTextBox.Text)) { 423 | $tenantIDTextBox.Text = "$tenantIDTextBoxDefaultText" 424 | $tenantIDTextBox.ForeColor = [System.Drawing.Color]::Gray 425 | } 426 | }) 427 | 428 | # Event handler for deleting selected rows 429 | $deleteButton.Add_Click({ 430 | foreach ($row in $dataGridViewSelected.SelectedRows) { 431 | $packageID = $row.Cells['PackageID'].Value 432 | $dataGridViewSelected.Rows.Remove($row) 433 | Write-ConsoleTextBox "Removed '$PackageID' from import list" 434 | 435 | } 436 | 437 | # Autosize columns after deleting rows 438 | $dataGridViewSelected.AutoResizeColumns([System.Windows.Forms.DataGridViewAutoSizeColumnMode]::AllCells) 439 | }) 440 | # Event handler for importing CSV 441 | $importCSVButton.Add_Click({ 442 | $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog 443 | $openFileDialog.InitialDirectory = (Get-Location).Path 444 | $openFileDialog.Filter = "CSV files (*.csv)|*.csv" 445 | 446 | $result = $openFileDialog.ShowDialog() 447 | if ($result -eq [System.Windows.Forms.DialogResult]::OK) { 448 | $csvFilePath = $openFileDialog.FileName 449 | 450 | # Load CSV data into a PowerShell object 451 | $importedData = Import-Csv -Path $csvFilePath 452 | 453 | # Clear existing rows in $dataGridViewSelected 454 | $dataGridViewSelected.Rows.Clear() 455 | 456 | # Add rows to $dataGridViewSelected from imported data 457 | foreach ($row in $importedData) { 458 | $dataGridViewSelected.Rows.Add( 459 | $row.PackageID, 460 | $row.Context, 461 | $row.AcceptNewerVersion, 462 | $row.UpdateOnly, 463 | $row.TargetVersion, 464 | $row.StopProcessInstall, 465 | $row.StopProcessUninstall, 466 | $row.PreScriptInstall, 467 | $row.PostScriptInstall, 468 | $row.PreScriptUninstall, 469 | $row.PostScriptUninstall, 470 | $row.CustomArgumentListInstall, 471 | $row.CustomArgumentListUninstall, 472 | $row.InstallIntent, 473 | $row.Notification, 474 | $row.GroupID 475 | ) 476 | } 477 | } else { 478 | $dataGridViewSelected.Rows.Clear() 479 | } 480 | 481 | # Autosize columns in $dataGridViewSelected after import 482 | $dataGridViewSelected.AutoResizeColumns([System.Windows.Forms.DataGridViewAutoSizeColumnMode]::AllCells) 483 | }) 484 | 485 | # Event handler for exporting CSV 486 | $exportButton.Add_Click({ 487 | # Check if DataGridView is not empty 488 | if ($dataGridViewSelected.Rows.Count -gt 0) { 489 | # Create an empty array to store the selected data 490 | $selectedData = @() 491 | 492 | # Iterate through DataGridView rows 493 | foreach ($row in $dataGridViewSelected.Rows) { 494 | $packageID = $row.Cells['PackageID'].Value 495 | $context = $row.Cells['Context'].Value 496 | $acceptNewerVersion = $row.Cells['AcceptNewerVersion'].Value 497 | $updateOnly = $row.Cells['UpdateOnly'].Value 498 | 499 | # Check if all required values are not null or empty 500 | if ($packageID -ne $null -and $packageID -ne '' -and 501 | $context -ne $null -and $context -ne '' -and 502 | $acceptNewerVersion -ne $null -and $acceptNewerVersion -ne '' -and 503 | $updateOnly -ne $null -and $updateOnly -ne '') { 504 | # Create a hashtable representing the row data and add it to the selected data array 505 | $rowData = [ordered]@{ 506 | 'PackageID' = $packageID 507 | 'Context' = $context 508 | 'AcceptNewerVersion' = $acceptNewerVersion 509 | 'UpdateOnly' = $updateOnly 510 | 'TargetVersion' = $row.Cells['TargetVersion'].Value 511 | 'StopProcessInstall' = $row.Cells['StopProcessInstall'].Value 512 | 'StopProcessUninstall' = $row.Cells['StopProcessUninstall'].Value 513 | 'PreScriptInstall' = $row.Cells['PreScriptInstall'].Value 514 | 'PostScriptInstall' = $row.Cells['PostScriptInstall'].Value 515 | 'PreScriptUninstall' = $row.Cells['PreScriptUninstall'].Value 516 | 'PostScriptUninstall' = $row.Cells['PostScriptUninstall'].Value 517 | 'CustomArgumentListInstall' = $row.Cells['CustomArgumentListInstall'].Value 518 | 'CustomArgumentListUninstall' = $row.Cells['CustomArgumentListUninstall'].Value 519 | 'InstallIntent' = $row.Cells['InstallIntent'].Value 520 | 'Notification' = $row.Cells['Notification'].Value 521 | 'GroupID' = $row.Cells['GroupID'].Value 522 | } 523 | $selectedData += New-Object PSObject -Property $rowData 524 | } 525 | } 526 | 527 | # Check if any valid data was extracted 528 | if ($selectedData.Count -gt 0) { 529 | $defaultFileName = "WinGet-WrapperImportGUI-$timestamp.csv" 530 | $saveFileDialog = New-Object System.Windows.Forms.SaveFileDialog 531 | $saveFileDialog.InitialDirectory = (Get-Location).Path 532 | $saveFileDialog.FileName = $defaultFileName 533 | $saveFileDialog.Filter = "CSV files (*.csv)|*.csv" 534 | 535 | $result = $saveFileDialog.ShowDialog() 536 | if ($result -eq [System.Windows.Forms.DialogResult]::OK) { 537 | $csvFilePath = $saveFileDialog.FileName 538 | $selectedData | Export-Csv -Path $csvFilePath -NoTypeInformation 539 | Write-ConsoleTextBox "Exported: $csvFilePath" 540 | } else { 541 | Write-ConsoleTextBox "No data exported." 542 | } 543 | } else { 544 | Write-ConsoleTextBox "No valid data to export." 545 | } 546 | } else { 547 | Write-ConsoleTextBox "No data to export." 548 | } 549 | }) 550 | 551 | 552 | # Event handler for moving selected rows 553 | $moveButton.Add_Click({ 554 | $selectedRows = $dataGridView.SelectedRows 555 | foreach ($row in $selectedRows) { 556 | $name = $row.Cells['Name'].Value 557 | $id = $row.Cells['ID'].Value 558 | $version = $row.Cells['Version'].Value 559 | 560 | # Add a new row to $dataGridViewSelected 561 | $rowIndex = $dataGridViewSelected.Rows.Add() 562 | 563 | # Set the "PackageID" column with the value from the selected row's "Name" column 564 | $dataGridViewSelected.Rows[$rowIndex].Cells['PackageID'].Value = $id 565 | 566 | # Set default values for other columns 567 | $dataGridViewSelected.Rows[$rowIndex].Cells['Context'].Value = "Machine" 568 | $dataGridViewSelected.Rows[$rowIndex].Cells['AcceptNewerVersion'].Value = "1" 569 | $dataGridViewSelected.Rows[$rowIndex].Cells['UpdateOnly'].Value = "0" 570 | 571 | # Autosize columns in $dataGridViewSelected after adding rows and setting values 572 | $dataGridViewSelected.AutoResizeColumns([System.Windows.Forms.DataGridViewAutoSizeColumnMode]::AllCells) 573 | 574 | Write-ConsoleTextBox "Added '$id' to import list" 575 | 576 | # Optionally remove the row from the original DataGridView 577 | #$dataGridView.Rows.Remove($row) # Do not remove row after copy to selected datagridview 578 | } 579 | }) 580 | 581 | # Function to write Column Definitions to ConsoleWriteBox 582 | Function GetColumnDefinitions { 583 | # Fetch the content of the README.md file 584 | $url = "https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/main/README.md" 585 | Write-ConsoleTextBox "$url" 586 | $response = Invoke-WebRequest -Uri $url 587 | 588 | # Check if the request was successful 589 | if ($response.StatusCode -eq 200) { 590 | $content = $response.Content 591 | 592 | # Get column names dynamically from the DataGridView 593 | $columnNames = @() 594 | foreach ($column in $dataGridViewSelected.Columns) { 595 | $columnNames += $column.Name # Collect column names into an array 596 | } 597 | Write-ConsoleTextBox "Column Name --> Description" 598 | Write-ConsoleTextBox "****************************" 599 | # Loop through each column name 600 | foreach ($columnName in $columnNames) { 601 | # Use regex to find the line corresponding to the column name 602 | if ($content -match "\* $columnName\s*=\s*(.*?)
") { 603 | $description = $matches[1] -replace "
", "`n" -replace "\* ", "" # Clean up the description 604 | Write-ConsoleTextBox "$columnName --> $description" 605 | } else { 606 | Write-ConsoleTextBox "$columnName --> No description found." 607 | } 608 | } 609 | Write-ConsoleTextBox "****************************" 610 | } else { 611 | Write-ConsoleTextBox "Failed to retrieve the README file. Status code: $($response.StatusCode)" 612 | } 613 | } 614 | 615 | 616 | 617 | 618 | 619 | 620 | # Function to get WinGet package details for a single/selected package (to find possible winget values, system, versions, etc etc.) 621 | function WinGetPackageDetails { 622 | param ( 623 | [string]$PackageID 624 | ) 625 | 626 | # Get package details and available versions 627 | $WingetPackageDetails = winget show --id $PackageID --source WinGet --accept-source-agreements --disable-interactivity 628 | 629 | # Output package details line by line to maintain formatting 630 | Write-ConsoleTextBox "$PackageID - Details:" 631 | $WingetPackageDetails -split "`r?`n" | ForEach-Object { Write-ConsoleTextBox $_ } 632 | Write-ConsoleTextBox "_" # Separator for readability 633 | 634 | 635 | # Optionally return the available versions array for further processing 636 | return $WinGetPackageDetails 637 | } 638 | 639 | # Function to get WinGet package versions for a single/selected package (to find possible winget values, system, versions, etc etc.) 640 | function WinGetPackageVersions { 641 | param ( 642 | [string]$PackageID 643 | ) 644 | # Get package details and available versions 645 | $WingetPackageVersionsOutput = winget show --id $PackageID --source WinGet --versions 646 | 647 | # Output available versions header 648 | Write-ConsoleTextBox "$PackageID - Available Versions:" 649 | 650 | # Initialize an array for the available versions 651 | $WinGetPackageVersions = @() 652 | 653 | # Split version details into lines and filter out empty lines 654 | $versionLines = $WingetPackageVersionsOutput -split "`r?`n" | Where-Object { 655 | -not [string]::IsNullOrWhiteSpace($_) 656 | } 657 | 658 | # Skip the first three lines and process the remaining lines 659 | foreach ($line in $versionLines[3..($versionLines.Length - 1)]) { 660 | $trimmedLine = $line.Trim() # Trim whitespace 661 | if (-not [string]::IsNullOrWhiteSpace($trimmedLine) -and $trimmedLine -notmatch '^-+$') { # Check it's not empty or dashes 662 | $WinGetPackageVersions += $trimmedLine # Add to available versions array 663 | Write-ConsoleTextBox $trimmedLine # Display each version line 664 | } 665 | } 666 | 667 | # Return the available versions array for further processing 668 | return $WinGetPackageVersions # Return the array using the specified variable name 669 | } 670 | 671 | 672 | # Define a function to parse the search results 673 | function ParseSearchResults($searchResult) { 674 | Write-ConsoleTextBox "Parsing data..." 675 | $parsedData = @() 676 | $pattern = "^(.+?)\s+((?:[\w.-]+(?:\.[\w.-]+)+))\s+(\S.*?)\s*$" 677 | $searchResult -split "`n" | Where-Object { $_ -match $pattern } | ForEach-Object { 678 | $parsedName = $Matches[1].Trim() 679 | $parsedID = $Matches[2].Trim() 680 | $parsedID = $parsedID -replace 'ÔǪ', '' # Remove ellipsis character from ID 681 | $parsedVersion = $Matches[3].Trim() 682 | 683 | # Add parsed and cleaned data to the result 684 | $parsedData += [PSCustomObject]@{ 685 | 'Name' = $parsedName 686 | 'ID' = $parsedID 687 | 'Version' = $parsedVersion 688 | } 689 | } 690 | Write-ConsoleTextBox "Finished" 691 | return $parsedData 692 | 693 | } 694 | # Define the PerformSearch function that uses the parsing function 695 | function PerformSearch { 696 | $searchString = $searchBox.Text 697 | $searchErrorLabel.Text = "Searching for '$searchString'" 698 | 699 | #Update winget sources (to prevent source updating as part of results, wierd output) 700 | @(winget source update) 701 | 702 | # Search Logic 703 | if (![string]::IsNullOrWhiteSpace($searchString)) { 704 | Write-ConsoleTextBox "winget search --query $searchString --source WinGet --accept-source-agreements --disable-interactivity" 705 | $searchResult = @(winget search --query $searchString --source WinGet --accept-source-agreements --disable-interactivity) 706 | # Splitting the search result into lines for logging purposes 707 | $lines = $searchResult -split "`r`n" 708 | 709 | # Writing each line to the consoleTextBox 710 | foreach ($line in $lines) { 711 | Write-ConsoleTextBox $line 712 | } 713 | if ($searchResult -contains "No package found matching input criteria.") { 714 | $dataGridView.Rows.Clear() 715 | $searchErrorLabel.Text = "No WinGet package found for search query '$searchString'" 716 | } 717 | else { 718 | # Clear existing rows from DataGridView 719 | $dataGridView.Rows.Clear() 720 | 721 | # Parse the search result using the ParseSearchResults function 722 | $parsedSearchResult = ParseSearchResults -searchResult $searchResult | 723 | Where-Object { $null -ne $_.Name -and $_.Name -ne '' -and $_.Name.Trim() -ne '' } 724 | 725 | # Add parsed data to DataGridView 726 | $parsedSearchResult | ForEach-Object { 727 | $row = $dataGridView.Rows.Add($_.Name, $_.ID, $_.Version) 728 | } 729 | $searchErrorLabel.Text = "Found $($dataGridView.RowCount) packages for '$searchString'" 730 | } 731 | } else { 732 | $dataGridView.Rows.Clear() 733 | $searchErrorLabel.Text = "Please enter a search query." 734 | } 735 | } 736 | 737 | 738 | # Assign search function to the button click event 739 | $searchButton.Add_Click({ PerformSearch }) 740 | 741 | # Allow pressing Enter to trigger search 742 | $form.KeyPreview = $true 743 | $form.Add_KeyDown({ 744 | param($keySender, $keyEvent) 745 | if ($keyEvent.KeyCode -eq "Enter") { 746 | PerformSearch 747 | } 748 | }) 749 | 750 | # Event Handler for Get package details button 751 | $GetPackageDetails.Add_Click({ 752 | $selectedRows = $dataGridView.SelectedRows 753 | foreach ($row in $selectedRows) { 754 | $id = $row.Cells['ID'].Value 755 | WinGetPackageDetails -PackageID "$id" 756 | } 757 | }) 758 | 759 | # Event Handler for Get package versions button 760 | $GetPackageVersions.Add_Click({ 761 | $selectedRows = $dataGridView.SelectedRows 762 | foreach ($row in $selectedRows) { 763 | $id = $row.Cells['ID'].Value 764 | WinGetPackageVersions -PackageID "$id" 765 | } 766 | }) 767 | 768 | # Event handler for the "Import to InTune" button 769 | $InTuneimportButton.Add_Click({ 770 | Write-ConsoleTextBox "Started import to InTune.." 771 | 772 | # Check if $tenantIDTextBox.Text is empty, matches $tenantIDTextBoxDefaultText, or does not contain a dot 773 | if ([string]::IsNullOrWhiteSpace($tenantIDTextBox.Text) -or $tenantIDTextBox.Text -eq $tenantIDTextBoxDefaultText -or -not ($tenantIDTextBox.Text -like '*.*')) { 774 | Write-ConsoleTextBox "Please enter a valid Tenant ID before importing to InTune." 775 | return # Stop further execution 776 | } 777 | 778 | # List of files to check 779 | $filesToCheck = @( 780 | "WinGet-Wrapper.ps1", 781 | "WinGet-WrapperDetection.ps1", 782 | "WinGet-WrapperRequirements.ps1", 783 | "WinGet-WrapperImportFromCSV.ps1", 784 | "IntuneWinAppUtil.exe" 785 | ) 786 | 787 | $foundAllFiles = $true 788 | foreach ($file in $filesToCheck) { 789 | $fileFullPath = Join-Path -Path $scriptRoot -ChildPath $file 790 | 791 | if (-not (Test-Path -Path $fileFullPath -PathType Leaf)) { 792 | # File not found, write a message to the console text box 793 | Write-ConsoleTextBox "File '$file' was not found." 794 | $foundAllFiles = $false 795 | } 796 | else { 797 | # File found, write a message to the console text box 798 | Write-ConsoleTextBox "File '$file' was found." 799 | } 800 | } 801 | 802 | if ($foundAllFiles) { 803 | Write-ConsoleTextBox "All required files found. Continue import to InTune..." 804 | 805 | # Export DataGridViewSelected to CSV - Save CSV Temporary 806 | $selectedData = @() 807 | 808 | # Check if DataGridView is not empty 809 | if ($dataGridViewSelected.Rows.Count -gt 0) { 810 | # Create an empty array to store the selected data 811 | $selectedData = @() 812 | 813 | # Iterate through DataGridView rows 814 | foreach ($row in $dataGridViewSelected.Rows) { 815 | $packageID = $row.Cells['PackageID'].Value 816 | $context = $row.Cells['Context'].Value 817 | $acceptNewerVersion = $row.Cells['AcceptNewerVersion'].Value 818 | $updateOnly = $row.Cells['UpdateOnly'].Value 819 | 820 | # Check if all required values are not null or empty 821 | if ($packageID -ne $null -and $packageID -ne '' -and 822 | $context -ne $null -and $context -ne '' -and 823 | $acceptNewerVersion -ne $null -and $acceptNewerVersion -ne '' -and 824 | $updateOnly -ne $null -and $updateOnly -ne '') { 825 | # Create a hashtable representing the row data and add it to the selected data array 826 | $rowData = [ordered]@{ 827 | 'PackageID' = $packageID 828 | 'Context' = $context 829 | 'AcceptNewerVersion' = $acceptNewerVersion 830 | 'UpdateOnly' = $updateOnly 831 | 'TargetVersion' = $row.Cells['TargetVersion'].Value 832 | 'StopProcessInstall' = $row.Cells['StopProcessInstall'].Value 833 | 'StopProcessUninstall' = $row.Cells['StopProcessUninstall'].Value 834 | 'PreScriptInstall' = $row.Cells['PreScriptInstall'].Value 835 | 'PostScriptInstall' = $row.Cells['PostScriptInstall'].Value 836 | 'PreScriptUninstall' = $row.Cells['PreScriptUninstall'].Value 837 | 'PostScriptUninstall' = $row.Cells['PostScriptUninstall'].Value 838 | 'CustomArgumentListInstall' = $row.Cells['CustomArgumentListInstall'].Value 839 | 'CustomArgumentListUninstall' = $row.Cells['CustomArgumentListUninstall'].Value 840 | 'InstallIntent' = $row.Cells['InstallIntent'].Value 841 | 'Notification' = $row.Cells['Notification'].Value 842 | 'GroupID' = $row.Cells['GroupID'].Value 843 | } 844 | $selectedData += New-Object PSObject -Property $rowData 845 | } 846 | } 847 | } 848 | if ($selectedData -ne $null -and $selectedData.Count -gt 0) { 849 | $fileName = "TempExport-$timestamp.csv" # Construct the filename with timestamp 850 | $csvFilePath = Join-Path -Path $scriptRoot -ChildPath $fileName # Save to script root directory 851 | $selectedData | Export-Csv -Path $csvFilePath -NoTypeInformation 852 | Write-ConsoleTextBox "Exported: $csvFilePath" 853 | } else { 854 | Write-ConsoleTextBox "No data to export." 855 | return # Stop further execution 856 | } 857 | 858 | # Prepare the Import script. 859 | $logFile = "$scriptRoot\Logs\WinGet_WrapperImportFromCSV_$($TimeStamp).log" 860 | $importScriptPath = Join-Path -Path $scriptRoot -ChildPath "Winget-WrapperImportFromCSV.ps1" 861 | Write-ConsoleTextBox "ImportScriptPath: $importScriptPath" 862 | 863 | #Inform user log file location: 864 | Write-ConsoleTextBox "****************************************************" 865 | Write-ConsoleTextBox "See log file for progress: $logFile" 866 | Write-ConsoleTextBox "****************************************************" 867 | 868 | #Run The Import Script 869 | # Define the arguments to be passed to the script 870 | $arguments = "-csvFile `"$csvFilePath`" -TenantID $($tenantIDTextBox.Text) -LogFile `"$logFile`" -ScriptRoot `"$scriptRoot`" -SkipConfirmation -SkipModuleCheck" 871 | Write-ConsoleTextBox "Arguments to be passed: $arguments" 872 | #Set-ExecutionPolicy Bypass -Scope Process -ExecutionPolicy Bypass -Force 873 | Start-Process powershell -ArgumentList "-NoProfile", "-ExecutionPolicy Bypass", "-File `"$importScriptPath`"", $arguments -Wait -NoNewWindow 874 | 875 | # Run Update-GUIFromLogFile in the main thread 876 | Start-Sleep -Seconds 5 # wait log file creation before reading it 877 | Update-GUIFromLogFile -logFilePath "$logFile" 878 | 879 | # Remove TempExport-$timestamp.csv 880 | if (Test-Path $csvFilePath) { 881 | Remove-Item $csvFilePath -Force 882 | Write-ConsoleTextBox "File $csvFilePath deleted successfully." 883 | } else { 884 | Write-ConsoleTextBox "File $csvFilePath not found." 885 | } 886 | 887 | Write-ConsoleTextBox "****************************************************" 888 | Write-ConsoleTextBox "Import Log File: $logFile" 889 | Write-ConsoleTextBox "****************************************************" 890 | } else { 891 | Write-ConsoleTextBox "Not all required files were found. Code will not run." 892 | } 893 | }) 894 | 895 | # Update ConsoleProgress 896 | Show-ConsoleProgress -PercentComplete 100 -Status "Sucessfully loaded Winget-Wrapper Import GUI" 897 | 898 | # Greeting 899 | Write-ConsoleTextBox "****************************************************" 900 | Write-ConsoleTextBox " WinGet-Wrapper" 901 | Write-ConsoleTextBox " https://github.com/SorenLundt/WinGet-Wrapper" 902 | Write-ConsoleTextBox "" 903 | Write-ConsoleTextBox " GNU General Public License v3" 904 | Write-ConsoleTextBox "****************************************************" 905 | 906 | # Show form 907 | $form.ShowDialog() | Out-Null -------------------------------------------------------------------------------- /WinGet-WrapperRequirements.ps1: -------------------------------------------------------------------------------- 1 | # Soren Lundt - 22-08-2023 2 | # URL: https://github.com/SorenLundt/WinGet-Wrapper 3 | # License: https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/main/LICENSE.txt 4 | # Requirements script to check if desired application is installed. To be used when only wanting to update the application if already installed. (UpdateOnly) 5 | # 6 | # Version History: 7 | # Version 1.0 - 22-08-2023 SorenLundt - Initial version. 8 | # Version 1.1 - 24-08-2023 SorenLundt - Adding automatically detection if running in user or system context. Removing Context parameter 9 | # Version 1.2 - 24-08-2023 SorenLundt - WindowStyle Hidden for winget process + Other small fixes.. 10 | # Version 1.3 - 25-08-2023 SorenLundt - Removing logging part. The script must only output "Installed" or "Not Installed" 11 | # Version 1.4 - 24-08-2023 SorenLundt - Added --scope $Context to winget cmd to avoid detecting applications in wrong context 12 | # Version 1.5 - 20-10-2023 SorenLundt - Fixed issues where applications containing + would not be detected.. Regex issue 13 | 14 | # Settings 15 | $id = "Exact WinGet Package ID" # WinGet Package ID - ex. VideoLAN.VLC 16 | # EndSettings 17 | 18 | #Define common variables 19 | $timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" 20 | $logPath = "$env:ProgramData\WinGet-WrapperLogs" 21 | $stdout = "$logPath\StdOut-$timestamp.txt" 22 | $errout = "$logPath\ErrOut-$timestamp.txt" 23 | 24 | #Determine if running in system or user context 25 | if ($env:USERNAME -like "*$env:COMPUTERNAME*") { 26 | $Context = "Machine" 27 | } 28 | else { 29 | $Context = "User" 30 | } 31 | 32 | # Find WinGet.exe Location 33 | if ($Context -contains "Machine"){ 34 | try { 35 | $resolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" 36 | if ($resolveWingetPath) { 37 | $wingetPath = $resolveWingetPath[-1].Path 38 | $wingetPath = $wingetPath + "\winget.exe" 39 | #Write-Output "WinGet path: $wingetPath" 40 | } 41 | else { 42 | Write-Output "Failed to find WinGet path" 43 | exit 1 44 | } 45 | } 46 | catch { 47 | Write-Output "Failed to find WinGet path: $($_.Exception.Message)" 48 | exit 1 49 | } 50 | } 51 | else{ 52 | # Running in user context. Set WingetPath 53 | $wingetPath = "winget.exe" 54 | } 55 | 56 | # Get version installed locally on machine 57 | $InstalledVersion = $null # Clear Variable 58 | try { 59 | Start-Process -FilePath $wingetPath -ArgumentList "list $id --exact --accept-source-agreements --scope $Context" -WindowStyle Hidden -Wait -RedirectStandardOutput $stdout 60 | $searchString = Get-Content -Path $stdout 61 | Remove-Item -Path $stdout -Force 62 | 63 | # Check if $searchString contains + character 64 | if ($searchString -match '\+') { 65 | # Remove + character from $id 66 | $searchString = $searchString -replace '\+', ' ' 67 | # Remove + character from $id 68 | $id = $id -replace '\+', ' ' 69 | } 70 | 71 | $versions = [regex]::Matches($searchString, "(?m)^.*$id\s*(?:[<>]?[\s]*)([\d.]+).*?$").Groups[1].Value 72 | 73 | if ($versions) { 74 | $InstalledVersion = ($versions | sort {[version]$_} | select -Last 1) 75 | Write-Output "Installed" 76 | exit 0 77 | } 78 | else { 79 | Write-Output "Not Installed" 80 | exit 0 81 | } 82 | } catch { 83 | Write-Output "Not Installed" 84 | exit 0 85 | } -------------------------------------------------------------------------------- /Winget-Wrapper.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SorenLundt/WinGet-Wrapper/f70477b2660d18c6b5f978e5df4fbfc96863f052/Winget-Wrapper.ico --------------------------------------------------------------------------------