Copy file remotely with PowerShell

Simply use the administrative shares to copy files between systems. It’s much easier this way. By using UNC paths instead of local filesystem paths, you help to ensure that your script is executable from any client system with access to those UNC paths. If you use local filesystem paths, then you are cornering yourself into … Read more

How to decode a Base64 string?

Isn’t encoding taking the text TO base64 and decoding taking base64 BACK to text? You seem be mixing them up here. When I decode using this online decoder I get: not the other way around. I can’t reproduce it completely in PS though. See sample below: EDIT I believe you’re using the wrong encoder for your text. The … Read more

PowerShell ‘Or’ Statement

The operator is -or, not or. See about_Logical_Operators. Also, if statements don’t read from the pipeline. Either put the if statement in a ForEach-Object loop: or use a Where-Object statement instead: And you can’t use property names by themselves. Use the current object variable ($_) to access properties of the current object. For checking if an attribute has one of a given number of values you can also … Read more

Function return value in PowerShell

PowerShell has really wacky return semantics – at least when viewed from a more traditional programming perspective. There are two main ideas to wrap your head around: All output is captured, and returned The return keyword really just indicates a logical exit point Thus, the following two script blocks will do effectively the exact same … Read more

How to write to the console in PowerShell?

Default behaviour of PowerShell is just to dump everything that falls out of a pipeline without being picked up by another pipeline element or being assigned to a variable (or redirected) into Out-Host. What Out-Host does is obviously host-dependent. Just letting things fall out of the pipeline is not a substitute for Write-Host which exists for the sole reason of outputting text … Read more

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

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