Access PSObject property indirectly with variable

No, there is no special syntax, but there is a simple workaround, using iex, the built-in alias[1] for the Invoke-Expression cmdlet: $propertyPath=”a.b” # Note the ` (backtick) before $json, to prevent premature expansion. iex “`$json.$propertyPath” # Same as: $json.a.b # You can use the same approach for *setting* a property value: $newValue=”foo” iex “`$json.$propertyPath = … Read more

‘kubectl patch’ works on Linux Bash but not in Windows Powershell ISE

For detailed and very useful background, see the answer by mklement0 After much frustration, I have decided to list all variants of quote escaping that I’ve tried, and came up with one more, which suddenly worked! So, sharing it here: kubectl patch deployment wapi-backend-d1 –patch ‘{\”spec\”: {\”template\”: {\”metadata\”: {\”labels\”: {\”date\”: \”test123\”}}}}}’ This is how to … Read more

Powershell, File system provider, Get-ChildItem filtering… where are the official docs?

tl;dr -Filter uses .NET’s implementation of FsRtllsNameInExpression, which is documented on MSDN along with basic pattern matching info. The algorithm is unintuitive for compatibility reasons, and you should probably avoid using this feature. Additionally, .NET has numerous bugs in its implementation. -Filter does not use the filtering system provided by PowerShell–that is, it does not … Read more

PowerShell and process exit codes

Current as of PowerShell [Core] 7.2.1 PowerShell-internal use of exit codes: PowerShell-internally, where native PowerShell commands generally run in-process, exit codes from child processes that run external programs play a very limited role: Native PowerShell commands generally don’t set exit codes and don’t act on them. PowerShell has an abstract counterpart to exit codes: $?, … Read more

Parsing xml using powershell

First step is to load your xml string into an XmlDocument, using powershell’s unique ability to cast strings to [xml] $doc = [xml]@’ <xml> <Section name=”BackendStatus”> <BEName BE=”crust” Status=”1″ /> <BEName BE=”pizza” Status=”1″ /> <BEName BE=”pie” Status=”1″ /> <BEName BE=”bread” Status=”1″ /> <BEName BE=”Kulcha” Status=”1″ /> <BEName BE=”kulfi” Status=”1″ /> <BEName BE=”cheese” Status=”1″ /> </Section> … Read more