Bomgar Representative Console session via PS
That works perfectly! Thanks! I'll post my script (scrubbed) when complete. It takes information from a database and posts it to RDM.
Bomgar Representative Console session via PS
Sent an email with information.
Cheers
Bomgar Representative Console session via PS
I would like to do this, I wrote one to add teamviewer sessions.
Can you give me a basic shell to work with?
Bomgar Representative Console session via PS
I would like to add Bomgar Representative Console session via powershell is this possible?
Scheduled powershell task issue
Confirmed resolved!
Scheduled powershell task issue
Finally had a chance to test this, and so far so good the updated version appears to work. I'll keep an eye on it today and confirm.
Scheduled powershell task issue
Removing norefresh didn't seem to make a bit of difference. Is it somehow related to the way it's scheduled? I can' understand why when I run the script in a loop it works fine until I schedule it to run once an hour.
edited by kstonernasg on 7/18/2014
Scheduled powershell task issue
something I just noticed, when I right click>clipboard>copy the session disappears.
Scheduled powershell task issue
first run:
<?xml version="1.0"?>
<ArrayOfConnection>
<Connection>
<ActiveDirectoryConsole />
<ConnectionType>TeamViewer</ConnectionType>
<CreatedBy>Domain\kstoner</CreatedBy>
<CreationDateTime>2014-07-16T14:32:00.1112706-05:00</CreationDateTime>
<Events />
<ID>c9291477-ce0d-4acc-a14c-9ff58ee7d238</ID>
<MetaInformation>
<PasswordHistory>
<PasswordHistory>
<ModifiedBy>Domain\kstoner</ModifiedBy>
<ModifiedDateTime>2014-07-16T14:32:02.1424426-05:00</ModifiedDateTime>
<SafePassword>scrubbed==</SafePassword>
</PasswordHistory>
</PasswordHistory>
</MetaInformation>
<Name>Stewart, Stacey - Domain-1362</Name>
<OpenEmbedded>true</OpenEmbedded>
<Stamp>a122905a-f929-462c-9b14-17cce222bae4</Stamp>
<TeamViewer>
<ID>12345678</ID>
<SafePassword>scrubbed==</SafePassword>
</TeamViewer>
<UpdateDateTime>2014-07-16T14:32:02.1424426-05:00</UpdateDateTime>
<UpdatedBy>Domain\kstoner</UpdatedBy>
</Connection>
</ArrayOfConnection>
after 2nd run:
<?xml version="1.0"?>
<ArrayOfConnection>
<Connection>
<ActiveDirectoryConsole />
<ConnectionType>TeamViewer</ConnectionType>
<CreatedBy>Domain\kstoner</CreatedBy>
<CreationDateTime>2014-07-16T14:39:34.9844278-05:00</CreationDateTime>
<Events />
<ID>aa452206-4d5a-42b8-bb9a-cd098cc65aa4</ID>
<MetaInformation>
<PasswordHistory>
<PasswordHistory>
<ModifiedBy>Domain\kstoner</ModifiedBy>
<ModifiedDateTime>2014-07-16T14:39:36.8593558-05:00</ModifiedDateTime>
<SafePassword>scrubbed==</SafePassword>
</PasswordHistory>
</PasswordHistory>
</MetaInformation>
<Name>Stewart, Stacey - Domain-1362</Name>
<OpenEmbedded>true</OpenEmbedded>
<Stamp>b4029959-c77d-47bf-99ac-6330805b76b3</Stamp>
<TeamViewer>
<ID>12345678</ID>
<SafePassword>scrubbed==</SafePassword>
</TeamViewer>
<UpdateDateTime>2014-07-16T14:39:36.8593558-05:00</UpdateDateTime>
<UpdatedBy>Domain\kstoner</UpdatedBy>
</Connection>
</ArrayOfConnection>
note scrubbed PW and changed teamviewer ID, the id was identical between them.
Scheduled powershell task issue
Will run it again and post the output. I currently do not have any security groups.
Scheduled powershell task issue
It appears to be the user account that powershell is launched with, If I use my account to run: Get-RDM-Session | where {$_.Session.Kind -eq "TeamViewer"} I get all the TV accounts. If I run it with a different account (admin) I get either no or different results.
Anyway to fix this? I would like to update the record no matter who put it in.
Scheduled powershell task issue
CMD script:
start /wait %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File UpdateRDM.ps1
exit
PS Script:
#********************************************
#* Script to update Teamvier session names *
#* Written by Ken Stoner *
# Updated 07-15-2014 14:39 *
#********************************************
Get-PSSnapin -Name *Remote.Desktop* -Registered | % { Write-Host "$_..." -NoNewline; if ( (Get-PSSnapin -Name $_ -ErrorAction SilentlyContinue) -eq $null ) { Write-Host "installing" -ForegroundColor Yellow; Add-PsSnapin $_ } else { Write-Host "already installed" -ForegroundColor Green; } }
$ServerName = "DBSERVER"
$DatabaseName = "Teamviewer"
$Query = "Select distinct rtrim(ltrim(TVId)) as TVID, CombinedName, rtrim(ltrim(Location)) as Location from (SELECT *,MaxDate= Max([LastUpdate])OVER (PARTITION BY TVId)FROM [Teamviewer].[dbo].[TeamViewerID]) as s where LastUpdate = MaxDate and len(TVId) <>0"
#Timeout parameters
$QueryTimeout = 120
$ConnectionTimeout = 30
#Action of connecting to the Database and executing the query and returning results if there were any.
$conn=New-Object System.Data.SqlClient.SQLConnection
$ConnectionString = "Server={0};Database={1};Integrated Security=True;Connect Timeout={2}" -f $ServerName,$DatabaseName,$ConnectionTimeout
$conn.ConnectionString=$ConnectionString
$conn.Open()
$cmd=New-Object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.CommandTimeout=$QueryTimeout
$ds=New-Object system.Data.DataSet
$da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
[void]$da.fill($ds)
$conn.Close()
$dataTable = $ds.Tables[0]
#Get existing sessions "Teamviwer"
$sessions = Get-RDM-Session | where {$_.Session.Kind -eq "TeamViewer"}
#Get the Teamviwer ID inside from the session
$TVIDs = $sessions.Session.GetProperty("TeamViewer", "ID")
$UpdateCount = 0
$AddCount = 0
#Update the Sessions or add them
$dataTable | FOREACH-OBJECT {
Write-Host " "
$HostTVId= $_.TVId
$HostName= $_.CombinedName
$HostLocation = $_.Location + "\TeamViewer"
Write-Host "Returned From SQL (HostName: "$HostName " TeamViewerID: " $HostTVId " Location: " $HostLocation -foreground "Magenta"
if ($TVIDs -contains $HostTVId)
{
#Update session name
Write-Host "Updating:" $HostName -foreground "Yellow"
$UpdateSession = Get-RDM-Session |where {$_.Session.getProperty("TeamViewer", "ID") -eq $HostTVId}
$UpdateSession[0].Session.Name = $HostName
$UpdateSession[0].Session.Group = $HostLocation
Set-RDM-Session $UpdateSession[0].Session -NoRefresh;
$UpdateCount = $UpdateCount + 1
}
else
{
#Add Session name
Write-Host "Adding:" $HostName
$session = New-RDM-Session -Name $HostName -Kind "TeamViewer"
$session.Group = $HostLocation
$session.TeamViewer.ID = $HostTVId;
Set-RDM-Session $session -NoRefresh;
$pass = ConvertTo-SecureString "PWHere" -asplaintext -force;
Set-RDM-Password -ID $session.ID -Password $pass -NoRefresh;
$AddCount = $AddCount + 1
}
}
Write-Host " "
Write-Host "Sessions Updated:" $UpdateCount -foreground "White"
Write-Host "Sessions Added:" $AddCount -foreground "White"
Start-Sleep -s 10
Seems everytime the scheduler kicks it off a new session is created. However if I run the cmd file from a prompt it works fine every time. I've tried using an admin account and a system account to run the task.
Scheduled powershell task issue
I have noticed that when my powershell script to update or add new teamviewer sessions will always add a new session to the database, os there a way around it?
Manually kicking off the scrip works normally, however when it runs as a scheduled task it's creating new sessions with the same information.
Let me know if I can provide more information. Using the current Beta 9.4.9.0
Teamviewer session update via powershell
Thanks! Got it working and added it to the repository.
Update Teamviewer sessions based on database table
Original help question is here: http://forum.devolutions.net/topic16163-teamviewer-session-update-via-powershell.aspx
I had a need to update our sessions based on the name of the logged on user. We use a logon script that collects the username and teamviewer id and places into a database. Using the Powershell script below updates the names of the teamviewer sessions.
Database:
USE [Teamviewer]
GO
/****** Object: Table [dbo].[TeamViewerID] Script Date: 7/9/2014 12:31:09 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeamViewerID](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[TVId] [nchar](10) NULL,
[ComputerName] [nvarchar](50) NULL,
[UserName] [nvarchar](50) NULL,
[CombinedName] [nvarchar](50) NULL,
[LastUpdate] [smalldatetime] NULL
) ON [PRIMARY]
GO
Logon script:
'****************************************
'* Teamviewer ID to Database Script *
'* Written by Ken Stoner *
'* For Teamviewer versions: 8,9 *
'****************************************
Dim allComp(500,4)
Dim arrStr, count2
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Function EnvString(variable)
set objShell = WScript.CreateObject( "WScript.Shell" )
variable = "%" & variable & "%"
EnvString = objShell.ExpandEnvironmentStrings(variable)
Set objShell = Nothing
End Function
'Get Enviromental Vars
'user=lcase(EnvString("username"))
strLocalComputer=ucase(EnvString("ComputerName"))
'domain=lcase(EnvString("UserDomain"))
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Wow6432Node\TeamViewer\Version8"
strValueName = "ClientID"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
if len(dwValue) >= 9 then TVID = dwValue end if
if len(TVID) < 1 then
strKeyPath = "SOFTWARE\Wow6432Node\TeamViewer\Version9"
strValueName = "ClientID"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
if len(dwValue) >= 9 then TVID = dwValue end if
end if
Set oNetwork = CreateObject("WScript.Network")
sDomain = oNetwork.UserDomain
sUser = oNetwork.UserName
sADSPath= sDomain & "/" & sUser
Set oUser = GetObject("WinNT://" & sADSPath & ",user")
strUser = oUser.FullName
NewName = strUser & " - " & strLocalComputer
Dim conn, connectString, strSQL
Set conn=CreateObject("ADODB.Connection")
connectString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=username;Data Source=databaseservername;Password=password;DATABASE=Teamviewer"
conn.open connectString
strSQL="INSERT INTO TeamViewerID ([TVId],[ComputerName],[UserName],[CombinedName],[LastUpdate]) VALUES ('" & TVId & "','" & strLocalComputer & "','" & strUser & "','" & NewName & "','" & Now & "')"
'MsgBox strSQL
Dim objRS
Set objRS = Conn.Execute(strSQL,Rows)
Conn.Close
Set objRS = Nothing
wscript.quit
PowerShell to update RDM:
#********************************************
#* PS script to update Teamvier session names *
#* Written by Ken Stoner *
#********************************************
$ServerName = "databaseserver"
$DatabaseName = "Teamviewer"
$Query = "Select distinct rtrim(ltrim(TVId)) as TVID, CombinedName from (SELECT *,MaxDate= Max([LastUpdate])OVER (PARTITION BY TVId)FROM [Teamviewer].[dbo].[TeamViewerID]) as s where LastUpdate = MaxDate and len(TVId) <>0"
#Timeout parameters
$QueryTimeout = 120
$ConnectionTimeout = 30
#Action of connecting to the Database and executing the query and returning results if there were any.
$conn=New-Object System.Data.SqlClient.SQLConnection
$ConnectionString = "Server={0};Database={1};Integrated Security=True;Connect Timeout={2}" -f $ServerName,$DatabaseName,$ConnectionTimeout
$conn.ConnectionString=$ConnectionString
$conn.Open()
$cmd=New-Object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.CommandTimeout=$QueryTimeout
$ds=New-Object system.Data.DataSet
$da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
[void]$da.fill($ds)
$conn.Close()
$dataTable = $ds.Tables[0]
#Get existing sessions "Teamviwer"
$sessions = Get-RDM-Session | where {$_.Session.Kind -eq "TeamViewer"}
#Get the Teamviwer ID inside from the session
$TVIDs = $sessions.Session.GetProperty("TeamViewer", "ID")
#Update the Sessions or add them
$dataTable | FOREACH-OBJECT {
$HostTVId= $_.TVId
$HostName= $_.CombinedName
if ($TVIDs -contains $HostTVId)
{
#Update session name
$UpdateSession = Get-RDM-Session |where {$_.Session.getProperty("TeamViewer", "ID") -eq $HostTVId}
$UpdateSession.Session.Name = $HostName
Write-Host "Updating: " $UpdateSession.Session.Name
Set-RDM-Session $UpdateSession.Session -NoRefresh;
}
else
{
#Add Session name
Write-Host "Adding: " + $_.CombinedName
$session = New-RDM-Session -Name $_.CombinedName -Kind "TeamViewer"
$session.Group = "TeamViewer"
$session.TeamViewer.ID = $_.TVId;
Set-RDM-Session $session -NoRefresh;
$pass = ConvertTo-SecureString "PWHere" -asplaintext -force;
Set-RDM-Password -ID $session.ID -Password $pass -NoRefresh;
}
}
edited by kstonernasg on 7/16/2014
Teamviewer session update via powershell
Your best bet is to look at RDM's PowerShell module. You could write a script that does the renaming for you.
Online help: http://help.remotedesktopmanager.com/index.html?powershell_cmdlets.htm
PowerShell forum sample scripts: http://forum.devolutions.net/forum42-remote-desktop-manager--powershell-repository.aspx
Regards,
How do I then grab the Teamviewer ID (highlighted) to do the lookup?
Teamviewer session update via powershell
Actually we would search by the session name so I would search User B to find it. Basically I just want to change the session name on the record that has the TVId xxxxx or 1234 from the example above.
Teamviewer session update via powershell
Hello,
I have seen the script to import teamviewer sessions. I am however wondering if it's possible to update a session based on the teamviewer ID?
For instance we have a script that updates a databased with the logged on user and the teamviewer id of the machine. I would like to regularly update RDM with the logged on user-machinename based on it's id.
Example:
User A logs on to Machine1 and it has the TV Id 1234. in RDM it would show "User A - Machine1" id 1234
User A logs off then User B logs on TV Id is still 1234. During update cycle (script or whatnot) RPM would then show "User B - Machine1"
We don't always know what machine the user logs onto this would help use with searching them out.