远程运行.bat时访问被拒绝

时间:2019-11-18 20:16:15

标签: powershell batch-file access-denied

我正在尝试运行.bat在Windows服务器上安装CISCat心跳。这应该是一个相当简单的项目,但到目前为止,这让我很烦。

如果我在计算机上本地运行core命令,则不会出现问题

Start-Process '\\pdc-ciscatp01\CIS\cis-cat-centralized-ccpd.bat' -NoNewWindow -Wait

但是,当我运行远程脚本时,出现错误

  

由于错误而无法运行此命令:访问被拒绝。

下面是我当前的脚本。任何见识都会很棒。

$computers = Get-ADComputer -Filter * -SearchBase "OU=,OU=Administrative Area,DC=bob,DC=us"

foreach ($comp in $computers)

{
$ping = Test-Connection $comp.Name -Quiet -Count 1
if ($ping) 
  {

$Username = 'USER'
$Password = 'PASSWORD'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass



  Invoke-Command -ComputerName $comp.NAME -Scriptblock {Start-Process '\\pdc-ciscatp01\CIS\cis-cat-centralized-ccpd.bat' -NoNewWindow -Wait} -Credential $Cred -ErrorAction Stop


}} ```



0 个答案:

没有答案