[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk-13.0.2+8")
Microsoft PowerShell environment variable documentation
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk-13.0.2+8")
Microsoft PowerShell environment variable documentation
Many online file downloads have a checksum in the form of a ‘hash’ code, allowing you to verify the file integrity. This can be useful when downloaded via a 3rd party mirror or to see if a file is corrupted.
There is a handy PowerShell command for this: Get-FileHash
The -Algorithm parameter allows you to get the hash for different algorithms. Use <tab> to cycle through the available options.
Taking a LibreOffice mirror download as an example.
This is how easy it is to parse an XML file with PowerShell!
[xml]$xml = Get-Content .\data.xml
Example XML:
<?xml version="1.0" encoding="UTF-8"?> <Entries> <Entry Category="Animal">Dog</Entry> <Entry Category="Animal">Cat</Entry> <Entry Category="Animal">Cow</Entry> <Entry Category="City">New York</Entry> <Entry Category="City">Paris</Entry> <Entry Category="City">London</Entry> </Entries>
Example using the XML data:
foreach($em in $xml.Entries.Entry) { Write-Host "$($em.InnerText) is a type of $($em.Attributes['Category'].Value)" }
Dog is a type of Animal
Cat is a type of Animal
Cow is a type of Animal
New York is a type of City
Paris is a type of City
London is a type of City
XPath support is also built-in:
$xml.Entries.SelectNodes("//Entry[contains(@Category, 'City')]")
Category #text
-------- -----
City New York
City Paris
City London
To get more information on the return type of a statement use the GetType() method.