【问题标题】:Powershell GPUpdate @list - cannot connect to computers? Syntax?Powershell GPUpdate @list - 无法连接到计算机?句法?
【发布时间】:2014-08-01 18:12:00
【问题描述】:

当我运行下面的脚本时,我得到了:

PsExec v2.11 - 远程执行进程 版权所有 (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com

\■B: 无法访问 ■B: 找不到网络路径。 确保在 ■B 上启用了默认的 admin$ 共享。

我检查了computers.txt 列表是否有效(故意设置为仅在您现在要测试的那个上运行)

代码如下:

# refresh gp for logged in user
param(
$ouInfo
)

#make computer list
cls
Write-Host "Group Policy Update for User(s) on Remote Computer(s)`nBy xxxx`r" -ForegroundColor Yellow
$manOrAuto = Read-Host = "Enter computer name(s) Manually or Import from location? (m or i)"

if ($manOrAuto -eq "m")
    {
    New-Item c:\computers.txt -type file -Force
    cls
    Write-Host "Group Policy Update for User(s) on Remote Computer(s)`nBy Tom Gipson - txxxxx@xxxx`r" -ForegroundColor Yellow
    do {
    $computarList = Read-Host "Enter the name of the computer or IP address:"
    [string]$addSitesToList = "`r" + $computarList + "`r`n"
    Add-Content -Path c:\computers.txt -Value $addSitesToList
    Read-Host [string]$runAgain = "Add another? (y or n)"
    } while ($runAgain -eq "y")

    #update gp for logged in user
    Psexec.exe @c:\computers.txt Gpupdate.exe /Target:User /force
    }
    else {if ($manOrAuto -eq "i"){
    #get list of computers from AD
    New-Item c:\computers.txt -type file -Force
    cls
    Write-Host "Group Policy Update for User(s) on Remote Computer(s)`nBy xxxxxx - txxxx@vxxxxxx`r" -ForegroundColor Yellow

    #get location
    Write-Host "Locations:`r" -ForegroundColor Yellow
    Write-Host "xxxx`mxxxx`nxxxx`netc`n`r" -ForegroundColor Cyan
    $branchLocation = Read-Host "Enter the location from the list above and hit enter:"

    $ouInfoPrefix = "'OU=xxxxxxx,OU="
    $ouInfoSuffix = ",OU=xxxxx,OU=xxxxxx,dc=xxxxxxx,dc=local'"
    [string]$ouInfo = $ouInfoPrefix + $branchLocation + $ouInfoSuffix

    Get-ADComputer -SearchBase 'OU=Computers,OU=xxxxxx,OU=xxxxxx,OU=vxxxxx,dc=xxxxxx,dc=local' -Filter '*' | Select -Expand Name | Out-File c:\computers.txt
    Start-Sleep -Seconds 1
    Psexec.exe @c:\computers.txt cmd /c Gpupdate.exe /force
    }}

【问题讨论】:

  • 您想启动该行以由简单的命令解析器解析(我认为这是正确的术语,Keith Hill 会知道的)。执行PSExec.exe --% @c:\computers.txt gpupdate.exe /target:user /force 看看是否能解决问题。
  • @TheMadTechnician 谢谢——虽然它仍然给我相同的输出,但它不起作用。就像它认为列表中的第一台计算机是共享位置一样。列表中的第一个是:BR-TELL-01 如果有帮助的话

标签: powershell active-directory


【解决方案1】:

我能够通过将输出文件编码强制为 ASCII(默认为 Unicode)来解决此问题

out-file -encoding ASCII

【讨论】:

  • 啊,我以为 PowerShell 试图 Splat 一个由于 @ 符号而不存在的数组。很高兴你明白了。
  • 是的,我记得在使用 out-file 或 append 命令时它会吐出中文(字面意思)文本文件之前——ascii 编码修复了它
猜你喜欢
  • 2013-08-21
  • 2015-07-01
  • 2018-06-04
  • 1970-01-01
  • 2019-01-02
  • 2014-02-08
  • 2017-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多