powershell-core

Why is PowerShell applying the predicate of a `Where` to an empty list

廉价感情. 提交于 2020-08-19 09:06:27
问题 If I run this in PowerShell, I expect to see the output 0 (zero): Set-StrictMode -Version Latest $x = "[]" | ConvertFrom-Json | Where { $_.name -eq "Baz" } Write-Host $x.Count Instead, I get this error: The property 'name' cannot be found on this object. Verify that the property exists and can be set. At line:1 char:44 + $x = "[]" | ConvertFrom-Json | Where { $_.name -eq "Baz" } + ~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId :

How to parse HTML table with Powershell Core 7?

一曲冷凌霜 提交于 2020-06-08 11:50:14
问题 I have the following code: $html = New-Object -ComObject "HTMLFile" $source = Get-Content -Path $FilePath -Raw try { $html.IHTMLDocument2_write($source) 2> $null } catch { $encoded = [Text.Encoding]::Unicode.GetBytes($source) $html.write($encoded) } $t = $html.getElementsByTagName("table") | Where-Object { $cells = $_.tBodies[0].rows[0].cells $cells[0].innerText -eq "Name" -and $cells[1].innerText -eq "Description" -and $cells[2].innerText -eq "Default Value" -and $cells[3].innerText -eq

HtmlWebResponseObject.ParsedHtml replacement in Powershell Core 6

青春壹個敷衍的年華 提交于 2020-05-31 07:45:39
问题 My goal is to parse an html file retrieved with Invoke-WebRequest . If possible I'd like to avoid any external libraries. The problem I am facing is, that Invoke-WebRequest returns a BasicHtmlWebResponseObject instead of a HtmlWebResponseObject since Powershell 6. The Basic version misses the ParsedHtml property. Is there a good alternative to parse html in Powershell Core 6? I've tried to use Select-Xml but my html is not entirely valid (e.g. a missing closing tag), hence this fails to parse

How to automate either PowerShell or PowerShell Core for same machine

岁酱吖の 提交于 2020-05-28 05:30:27
问题 With the release of PowerShell Core, how can an application choose which version of Powershell (Powershell 5.x or PowerShell Core) is being called when it using hosting automation library (system.management.automation)? Something about the runspace that should be created? or maybe the connection info? 回答1: Here's an overview of the PowerShell SDK-related NuGet packages : Adapted from here. Microsoft.PowerShell.5.ReferenceAssemblies - for building Windows PowerShell applications, based on the

How to use Windows System.Speech for TTS in PowerShell 7 (or is there an alternative)

感情迁移 提交于 2020-05-23 10:24:32
问题 I have the same profile.ps1 in both WindowsPowerShell and PowerShell. It includes commands that invoke Windows Text-To-Speech However, these commands fail when run in PowerShell 7. The errors occur when I try to use the $PomrptTTS object I create with the following code: Add-Type -AssemblyName System.speech $PromptTTS = New-Object System.Speech.Synthesis.SpeechSynthesizer In PowerShell 7, any attempt to access or use my $PormptTTS object, produces the following: SetValueInvocationException: .