我已经阅读了在 PowerShell 中将 char 数组转换为字符串的各种方法,但它们似乎都不适用于我的字符串。我的字符串的来源是:
$ComputerName = "6WMPSN1"
$WarrantyURL = "http://www.dell.com/support/troubleshooting/au/en/aulca1/TroubleShooting/ProductSelected/ServiceTag/$ComputerName"
$WarrantyPage = Invoke-WebRequest -Uri $WarrantyURL
$WPageText = $WarrantyPage.AllElements | Where-Object {$_.id -eq "TopContainer"} | Select-Object outerText
生成的 WPageText 是一个字符数组,所以我不能使用 Select-String -Pattern "days" -Context
我试过了:
$WPageText -join
[string]::Join("", ($WPageText))
根据 http://softwaresalariman.blogspot.com.au/2007/12/powershell-string-and-char-sort-and.html
到目前为止,我唯一成功的事情是:
$TempFile = New-Item -ItemType File -Path $env:Temp -Name $(Get-Random)
$WPageText | Out-File -Path $TempFile
$String = Get-Content -Path $TempFile
除了写入和读取文件之外,还有什么方法可以做到这一点?