PowerShell string interpolation syntax

To complement marsze’s helpful answer: ${…} (enclosing the variable name in { and }) is indeed always necessary if a variable name contains special characters, such as spaces, ., or -. Not special are _ and – surprisingly and problematically – ?. Note: : is invariably interpreted as terminating a PowerShell drive reference, in the context of namespace variable notation, irrespective of whether {…} enclosure is used or required (e.g., in $env:USERNAME or ${env:USERNAME}, env refers to the PowerShell drive representing all environment variables). In the context … Read more

PowerShell and the -contains operator

The -Contains operator doesn’t do substring comparisons and the match must be on a complete string and is used to search collections. From the documentation you linked to: -Contains Description: Containment operator. Tells whether a collection of reference values includes a single test value. In the example you provided you’re working with a collection containing just one string … Read more

Array.Add vs +=

When using the $array.Add()-method, you’re trying to add the element into the existing array. An array is a collection of fixed size, so you will receive an error because it can’t be extended. $array += $element creates a new array with the same elements as old one + the new item, and this new larger array replaces the old … Read more

Prompt for user input in PowerShell

Read-Host is a simple option for getting string input from a user. To hide passwords you can use: To convert the password to plain text: As for the type returned by $host.UI.Prompt(), if you run the code at the link posted in @Christian’s comment, you can find out the return type by piping it to Get-Member (for example, $results | … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)