我已经阅读了在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
Run Code Online (Sandbox Code Playgroud)
生成的WPageText是一个Char数组,所以我不能使用Select-String -Pattern"days"-Context
我试过了:
$WPageText -join
[string]::Join("", ($WPageText))
Run Code Online (Sandbox Code Playgroud)
根据 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
Run Code Online (Sandbox Code Playgroud)
除了编写和读取文件之外,还有什么方法可以做到这一点?