Powershell远程执行不在远程计算机上写日志

时间:2014-09-15 12:51:20

标签: powershell logging installer remote-execution

我目前使用powershell脚本遇到了安装问题。我可以从命令行在主机B上运行脚本而没有任何问题。但是当我尝试远程启动时,脚本无法创建日志文件(我需要监视以查看何时需要将密码发送到命令行)。错误在最底层......

我从Host A启动安装程序(请参阅下面的命令)。它远程执行Host B上的powershell脚本cognosInstall.ps1。脚本代码位于底部。它开始复制文件并启动安装,但由于某种原因,它在创建日志文件时出现问题。我检查HostB上的本地目录,但也找不到该文件。

主机A(数据收集器):触发远程执行安装IBM Cognos的powershell脚本。

$s=new-pssession -computername HostB -credential $creds
invoke-command -session $s {$filename=Split-Path c:\temp\auto-install\*stats*.iso -leaf -resolve;echo $filename;}
invoke-command -session $s {c:\temp\auto-install\cognosInstall.ps1 $filename;}

主机B(正在安装Cognos):

#Open a command window
invoke-item C:\Windows\System32\cmd.exe
start-sleep -s 2

# Write output of install command to file 
select-window cmd |send-keys "c:\temp\cognos-install\cognos_install.bat c:\temp\cognos-install\cognos_mssql.ini C:\temp\IBM_Cognos_10.1.1_and_FP1 > c:\temp\Cognos_Install_log 2>&1 {ENTER}"

#check file for password prompt
do {
   Start-Sleep -s 8;
   write-output "Waiting for Password Prompt" 
   }
   until (Select-string -Path c:\temp\Cognos_Install_Log -pattern Password ) 
select-window cmd |send-keys "Passwd123{ENTER}"

我收到错误: 安装开始运行.....然后点击这个问题.....

Copying install config file to cognos-install directory
C:\temp\auto-install\cognos_mssql.ini
1 File(s) copied
Beginning of Cognos Install - wait for completion
Waiting for Password Prompt
Cannot find path 'C:\temp\Cognos_Install_Log' because it does not exist.
    + CategoryInfo          : ObjectNotFound: (C:\temp\Cognos_Install_Log:Stri 
    ng) [Select-String], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.Selec 
    tStringCommand

0 个答案:

没有答案