How can I find the product GUID of an installed MSI setup?

For upgrade code retrieval: How can I find the Upgrade Code for an installed MSI file? (or use the html table export script – shown below in section 2) Short Version The information below has grown considerably over time and may have become a little too elaborate. How to get product codes quickly? (four approaches): … Read more

Get-Aduser -Filter will not accept a variable

There is valuable information in the existing answers, but I think a more focused summary is helpful. Note that the original form of this answer advocated strict avoidance of script blocks ({…}) and AD-provider variable evaluation, but this has been replaced with more nuanced recommendations. tl;dr Get-ADUser -Filter ‘sAMAccountName -eq $SamAc’ Do not quote the … Read more

Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)

Note: This answer shows how to switch the character encoding in the Windows console to UTF-8 (code page 65001), so that shells such as cmd.exe and PowerShell properly encode and decode characters (text) when communicating with external (console) programs with full Unicode support, and in cmd.exe also for file I/O.[1] If, by contrast, your concern … Read more

Why should I avoid using the increase assignment operator (+=) to create a collection

Yes, the increase assignment operator (+=) should be avoided for building an object collection, see also: PowerShell scripting performance considerations. Apart from the fact that using the += operator usually requires more statements (because of the array initialization = @()) and it encourages to store the whole collection in memory rather then push it intermediately … Read more

How do I pass multiple parameters into a function in PowerShell?

Parameters in calls to functions in PowerShell (all versions) are space-separated, not comma separated. Also, the parentheses are entirely unneccessary and will cause a parse error in PowerShell 2.0 (or later) if Set-StrictMode -Version 2 or higher is active. Parenthesised arguments are used in .NET methods only. function foo($a, $b, $c) { “a: $a; b: … Read more

Powershell: null file always generated (output of Compare-Object)

PetSerAl, as he routinely does, has provided the crucial pointer in a comment on the question: Member-access enumeration – the ability to access a member (a property or a method) on a collection and have it implicitly applied to each of its elements, with the results getting collected in an array, was introduced in PSv3.[1] … Read more

Renaming files by reformatting existing filenames – placeholders in replacement strings used with the -replace operator

Martin Brandl’s answer provides an elegant and effective solution, but it’s worth digging deeper: PowerShell’s -replace operator (… -replace <search>[, <replace>]): Takes a regular expression as its first operand, <search> (the search expression), and invariably matches globally, i.e., it replaces all matches. ‘bar’ -replace ‘[ra]’, ‘@’ -> ‘b@@’ If you want to replace a literal … Read more