远程使用Get-ODBCDSN

时间:2018-09-19 14:33:55

标签: powershell odbc

我正在尝试编写一个PowerShell脚本,该脚本调用多个远程计算机并收集ODBC DSN用户/系统设置。我在下面有以下脚本,但是Get-ODBCDSN cmdlet似乎没有可以远程检索数据的属性。有没有人遇到这个问题并且能够提供一些帮助?

$servers = @("SERVER1","SERVER2")
$DSNs  = @("DSN1","DSN2")

foreach ($server in $servers)
{
    write-host `r`n "Getting DSN settings from "$server `r`n
    foreach ($DSN in $DSNs)
    {
        Get-ODBCDSN -name $DSN | Select Name, DsnType, platform, @{n='Description';e={$_.Attribute.server}}
        }
    Write-Output $results | sort name, dsntype
}

1 个答案:

答案 0 :(得分:0)

我知道这很古老,答案在评论中,但是让将来的观众更容易剪切和粘贴...

$servers = @("SERVER1","SERVER2")
$dsns = @("DSN1","DSN2")
foreach ($server in $servers) {
  foreach ($dsn in $dsns) {
    Invoke-Command -computername $server -command {
      Get-ODBCDSN -name $dsn | 
        Select Name, DsnType, @{n='Description';e={$_.Attribute.server}}
    }
    Write-Output $results | sort name, dsntype
  }
}