脚本不提示用户输入

时间:2019-03-27 13:21:16

标签: powershell

当我的脚本使用'run with powershell'选项执行时,不提示用户输入。但是,当我编辑脚本并使用PowerShell ISE工具运行它时,它的确提示用户输入。

$MGWServer = Read-Host 'Enter the name of the server where you want to copy the siteKey file from'

# variable to hold the objects of the list file for copying
$hostNameList = Get-Content D:\Temp\hostlist.txt

# copy file from source to destination
foreach ($hostName in $hostNameList)
{
    $TARGETDIR = "\\$hostName\D$\Temp\"

    Copy-Item -Path "\\$MGWServer\D$\Informatica\PowerCenter\isp\config\keys\siteKey" -Destination "$TARGETDIR\siteKey"
}

1 个答案:

答案 0 :(得分:0)

我无法使用最少的脚本重现您的问题:

$X = Read-Host 'Enter your text'
Write-Host $x 
Pause

从“使用Powershell运行”上下文菜单中执行时,脚本从主机读取并写入主机而没有问题。您的脚本路径中可能存在无效字符。尝试在循环的开头和循环中添加一个暂停,以检查所有错误。另外,请尝试从Powershell提示符而不是ISE运行它。