ip : 87.153.224.209 hostname : p5799e0d1.dip0.t-ipconnect.de city : Hannover region : Lower Saxony country : DE loc : 52.3705,9.7332 org : AS3320 Deutsche Telekom AG postal : 30159 timezone : Europe/Berlin readme : https://ipinfo.io/missingauth
通常,只有在真正的控制台窗口中才支持按键检测,因此这种方法不适用于 PowerShell ISE 和其他 PowerShell 宿主。
但是,PowerShell 可以从 Windows Presentation Foundation 中借用一种类型,这种类型可以检查任何键的状态。这样,实现在任何 PowerShell 脚本中都可以工作的“退出”键就变得很简单了,无论是在控制台、Visual Studio Code 还是 PowerShell ISE 中运行:
# choose the abort key $key = [System.Windows.Input.Key]::LeftCtrl
Write-Warning"PRESS $key TO ABORT!"
do { $isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key) if ($isCtrl) { Write-Host Write-Host"You pressed $key, so I am exiting!"-ForegroundColor Green break } Write-Host"."-NoNewline Start-Sleep-Milliseconds100 } while ($true)
# get some raw data that contains arrays $rawData = Get-EventLog-LogName System -Newest10 | Select-Object-Property TimeWritten, ReplacementStrings, InstanceId
# create this Excel file $Path = "$env:temp\report.xlsx" # make sure the file is deleted so we have no # effects from previous data still present in the # file. This requires that the file is not still # open and locked in Excel $exists = Test-Path-Path$Path if ($exists) { Remove-Item-Path$Path}
$sheetName = 'Testdata' $rawData | ForEach-Object { # convert column "ReplacementStrings" from array to string $_.ReplacementStrings = $_.ReplacementStrings -join"`r`n" # return the changed object $_ } | Export-Excel-Path$path-ClearSheet-WorksheetName$sheetName-Show
# get some raw data that contains arrays $rawData = Get-EventLog-LogName System -Newest10 | Select-Object-Property TimeWritten, ReplacementStrings, InstanceId
# create this Excel file $Path = "$env:temp\report.xlsx" # make sure the file is deleted so we have no # effects from previous data still present in the # file. This requires that the file is not still # open and locked in Excel $exists = Test-Path-Path$Path if ($exists) { Remove-Item-Path$Path}
$sheetName = 'Testdata'
# save the Excel object model by using -PassThru instead of -Show $excel = $rawData | ForEach-Object { # convert column "ReplacementStrings" from array to string $_.ReplacementStrings = $_.ReplacementStrings -join"`r`n" # return the changed object $_ } | Export-Excel-Path$path-ClearSheet-WorksheetName$sheetName-AutoSize-PassThru
#region Post-process the column with the misinterpreted formulas # remove the region to repro the original Excel error $sheet1 = $excel.Workbook.Worksheets[$sheetName] # reformat cell to number type "TEXT" with WordWrap and AutoSize Set-Format-Address$sheet1.Cells['B:B'] -NumberFormat'Text'-WrapText-AutoSize #endregion