→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tgibney
Engaged Sweeper
Powershell scripts were created to get information from network computers. The script's commands are to redirect output to a central share. That only happens when the scripts run on my PC but not on other's. Here's one script:

$HostName = hostname
$startdatetime = Get-Date -format "yyyyMMddHHmmss"
$TranscriptFile = -join("\\thepcname\PowershellRedirection\","Get-ODBC_DSNs",$StartDateTime,$hostname,".txt")
#ODBC DSN list before
get-odbcdsn | select-object name *> $TranscriptFile


And another script based on computer name with If logic:

$HostName = hostname
$startdatetime = Get-Date -format "yyyyMMddHHmmss"
$TranscriptFile = -join("\\server\PowershellRedirection\","ODBC_DSN_Install",$StartDateTime,$hostname,".txt")
#ODBC DSN list before
get-odbcdsn | select-object name *> $TranscriptFile

#A1
If($HostName -eq "computera") -or ($HostName -eq "computerb") -or ($HostName -eq "computerc"){
Add-OdbcDsn -Name "ODBCDSN1" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db2", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
}
#A1 and A2
If($HostName -eq "computerc") -or ($HostName -eq "computerb") -or ($HostName -eq "computerd") -or ($HostName -eq "computere") -or ($HostName -eq "computerf"){
Add-OdbcDsn -Name "ODBCDSN2" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db3", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
Add-OdbcDsn -Name "ODBCDSN3" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db4", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
Add-OdbcDsn -Name "ODBCDSN4" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db5", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
Add-OdbcDsn -Name "ODBCDSN5" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db6", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
Add-OdbcDsn -Name "ODBCDSN6" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db7", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
Add-OdbcDsn -Name "ODBCDSN7" -DriverName "ODBC Driver 17 for SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=dbserver2", "Trusted_Connection=Yes", "Database=db8", "Description=Driver Version 17 32-bit System DSN Type") -PassThru *>> $TranscriptFile
}
#ODBC DSN list after
get-odbcdsn | select-object name *>> $TranscriptFile


These will run on my PC. I believe they run on the list of deployed PCs when deployed using Lansweeper Command deployment but they do not report back.

TIA,
Tim
1 REPLY 1
tgibney
Engaged Sweeper
The issue is the "double hop" security issue. The fix is to use either Invoke-Command, PSSession, or CIMSession and capture output in the $ScriptBlock.