How to change tab width when converting to JSON in Powershell

Because the PowerShell’s ConvertTo-Json produces non-deterministic indentation, the current answers will not produce JSON that has exactly two spaces for each depth in the data structure. To get each level of nested data indented exactly two spaces more than the enclosing level requires rebuilding the indentation. (For what it’s worth, looks like this was fixed … Read more

How do I use PowerShell to Validate XML files against an XSD?

I want to comment that the script in current accepted answer doesn’t validate errors about incorrect orders of elements of xs:sequence. For example: test.xml <addresses xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=’test.xsd’> <address> <street>Baker street 5</street> <name>Joe Tester</name> </address> </addresses> test.xsd <xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”> <xs:element name=”addresses”> <xs:complexType> <xs:sequence> <xs:element ref=”address” minOccurs=”1″ maxOccurs=”unbounded”/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name=”address”> <xs:complexType> <xs:sequence> <xs:element ref=”name” … Read more

Extract private key from pfx file or certificate store WITHOUT using OpenSSL on Windows

I had the same problem and solved it with the help of PSPKI Powershell module from PS Gallery. While I understand that you look for a solution that preferably uses some built in functionality in Windows, installing a module from PS Gallery might be acceptable. At least it was in my case. First install the … Read more

PowerShell Add-WindowsFeature unrecognized

This is probably because the PowerShell script is being launched from a 32 bit instance of PowerShell. The ServerManager commands are only available from 64 bit version of PowerShell. See: Can’t access ServerManager module via PowerShell –Edit – To add to jbsmith’s comments— Extra things to try: When you ran the Get-Command cmdlt: gcm | … Read more

On Windows what is the difference between Git Bash vs Windows Power Shell vs Command prompt

Git bash is bash, which is IIRC also the default shell on MacOS. It is not the default shell on Windows, although several implementations exist (CygWin, MinGW, …). Git is bundled with a number of POSIX (UNIX/Linux/etc.) utilities in addition to bash; in order to avoid “collisions” with similarly named Windows commands, the most common … Read more

Get target of shortcut (.lnk) file with powershell

You have made an error in the property; as wOxxOm suggests, you should be using TargetPath rather than Target: $sh = New-Object -ComObject WScript.Shell $target = $sh.CreateShortcut(‘<full-path-to-shortcut>’).TargetPath Google and MSDN were indeed helpful here; additionally, piping objects to Get-Member can often be useful and educational. This question also shows how to manipulate shortcuts using PowerShell, … Read more

Powershell: Get-Item vs Get-ChildItem

Get-Item Gets the item at the specified location. Get-Item .\foo # returns the item foo Get-ChildItem Gets the items and child items in one or more specified locations. Get-ChildItem .\foo # returns all of the children within foo note: Get-ChildItem can also recurse into the child directories Get-ChildItem .\foo -Recurse # returns all of the … Read more