I have a sample script for my diploma and it uses keypress mechanism, like so:
echo "A text prompting you to pres Enter"
$key = [System.Windows.Input.Key]::Enter
do
{
$isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key)
if ($isCtrl)
{
$query = Get-Childitem 'D:\' -Recurse | Where-Object {$_.Name -match "controller.st$"}
foreach-object { $name = $query.FullName}
(Get-Content $name).Replace('A := AND55_OUT OR AND56_OUT OR AND61_OUT;', 'A := AND55_OUT') | Set-Content $name
#this actually does the replacing in a file
echo "sample text"
Start-Sleep -Seconds 30
echo "sample text"
break
}
} while ($true)
and the rest of the script continues.
I use the converting script
function Convert-PowerShellToBatch
{
param
(
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[string]
[Alias("FullName")]
$Path
)
process
{
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes((Get-Content -Path $Path -Raw -Encoding UTF8)))
$newPath = [Io.Path]::ChangeExtension($Path, ".bat")
"@echo off`npowershell.exe -NoExit -encodedCommand $encoded" | Set-Content -Path $newPath -Encoding Ascii
}
}
Get-ChildItem -Path C:\path\to\powershell\scripts -Filter *.ps1 |
Convert-PowerShellToBatch
and I modify this to my case but when I run the batch file, I get the following error:
Unable to find type [System.Windows.Input.Keyboard].
At line:7 char:11
+ $isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Input.Keyboard:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
What can I do to overcome this?