I will add, the GRID output will work as long as there are results for the Get-WMIObject call (and the servers being queried are online). I'm trying to catch for servers that aren't online and don't have any of the services found in Get-WMIObject.
I just updated to 6.1.10324 - Beta and still get the column mismatch.
Hi John,
unfortunately we cannot reproduce this error in our environment.
Can you please state which version of Royal TS and which OS version you are using?
One additional remark: Royal TS V6 uses .NET6 and this implies the usage of PowerShell Core which does not have the Get-WMIObject cmdlet anymore (it is recommended to use the CIM cmdlets).
best regards,
Michael
Hello Michael!
I'm using RoyalTS 6.1.10324 and connecting to Windows Server 2012 R2.
From further testing, it seems to be the creation of the Array in the ForEach loop. I'm working with a simpler script now and that's where it seems to be getting odd columns returned.
Is there anyway to turn on a verbose with RoyalTS?
Thanks,
John
Hi John,
yes, the exception "Columns do not match" points in the direction that there are objects with a different number of properties in it.
The Grid-Output in Royal TS uses the underlying DataTable for it. You can try to switch to "Text" output and check, which object has a different number of properties (aka columns)
Let me know if this helps.
cheers,
Michael
I think in this simpler script, the Server variable is not passing to PSObject.
function checkOBWinSvcs { param ($computer) $obWinSvcInfo = @() $system = $computer if (Test-Connection -ComputerName $computer -Count 1 -Quiet) { $obWinSvcs = Get-Service -ComputerName $computer -Name *OnBase* | Where { $_.status -eq 'RUNNING' } | Select-Object DisplayName, Status if ($obWinSvcs) { foreach ($obWinSvc in $obWinSvcs) { $objWinSvc = @{ DisplayName = $obWinSvc.DisplayName Status = $obWinSvc.Status Server = $system } # $objWinSvc $PSObject = New-Object -TypeName PSObject -Property $objWinSvc $obWinSvcInfo += $PSObject } # foreach ($obWinSvc in $obWinSvcs) } # if ($obWinSvcs.Count -gt 0) else { $obWinSvcInfo = [PSCustomObject] @{ DisplayName = "NO ONBASE WIN SVC" Status = "NONE" Server = $computer } # $obWinSvcInfo } #else ($obWinSvcs.Count -gt 0) } # if (Test-Connection -ComputerName $computer -Count 1 -Quiet) else { $obWinSvcInfo = [PSCustomObject] @{ DisplayName = "SERVER OFFLINE" Status = "NONE" Server = $computer } # $obWinSvcInfo } # else (Test-Connection -ComputerName $computer -Count 1 -Quiet) $obWinSvcInfo | Select-Object -Property DisplayName, Status, Server } #function checkOBWinSvcs -computer localhost
Text View displays all the columns I"m expecting but the Server column has localhost for each result instead of actual host name I'm querying.
Thanks!
Hi John,
I am not sure I understand what you want to achieve.
As far as i can see from the script, you pass "localhost" as a parameter to the function checkOBWinSvcs. So this should query localhost.
If you want to work with parameters passed from the outside (aka Royal TS), you can use parameters defined in the connection properties:
Note, that you can use Royal TS connection Variables here as well.
As for the "__Computername" column: this is a column that makes sense, if you query more than one machine within one connection.
E.g. you can enter the following in the computername property: "192.168.178.10;192.168.178.11" and the connection will be issued against two hosts - to distinguish the result colums, __Computername can be used.
Let me know if this helps
cheers,
Michael
Michael,
So I'm using the info from this post as my starting point...
New Feature: PowerShell Connection | Royal Apps
From a high level I'm looking to pass a remote computer name and perform the following...
1. Query Get-CimInstance -Classname Win32_Service for any Windows Service with '%OnBase%' in the DisplayName and IS NOT disabled.
2. For each "OnBase" service returned, grab various properties of each service
a. Take the <svc>.Name property and use that to query the remote computer's registry to grab additional properties for the service (OnBase stores these additional properties in a separate registry key for each <svc>.Name value)
b. Take all of the returned properties and add it to an array to then be output on screen
3. Do the above for each remote computer listed in the RoyalTS PowerShell Connection's Computer Name entry.
The script works great outside of RoyalTS (I'm able to grab everything and store it nicely in an Excel spreadsheet). Being able to use RoyalTS would be a plus as one could just open the Connection in RoyalTS and quickly see the info in a nice Grid output.
It seems to work fine when there are the exact services I'm looking to query exist and the remote server is online. It seems to choke when I start adding error checking for offline remote computers and remote computers that do not have the services being queried.
The localhost code I'm using is based on the example in the above link.
Thanks,
John
I finally figured it out!!! It's crazy, you start researching one issue, find examples to completely accomplish your task in a different way, try that one out, still have issue, fall down a rabbit hole but finally find your answer!
Turns out, there were some Object Properties that weren't coming back as a string, once I converted some of them...the grid view started working!
I still have get an error when I pass over a computer name that is mispelled or off the network (RoyalTS throws...
|
Is there any way to catch for this?
Thanks for everyone's help!
Here are my completed scripts....
function checkOBWinSvcs { param ($computer) $obWinSvcs = @() $obSvcs = @() $verbose = 0 $system = $Env:COMPUTERNAME if ($verbose -gt 0) { Write-Output "Working on $system!" } if (Test-Connection -ComputerName $computer -Count 1 -Quiet) { if ($verbose -gt 0) { Write-Output " - Hey, $system is online so we will continue processing..." } $obWinSvcs = Get-Service -ComputerName $computer -DisplayName *OnBase* | Where { $_.status -eq 'RUNNING' } #$obWinSvcs = Get-Service -ComputerName $computer | Where { $_.status -eq 'RUNNING' } if ($obWinSvcs) { if ($verbose -gt 0) { $cntObWinSvcs = $obWinSvcs.Count Write-Output " - We found $cntObWinSvcs services to process!" Write-Output "" } foreach ($obWinSvc in $obWinSvcs) { $strDisplayName = $obWinSvc.DisplayName $strStatus = $obWinSvc.Status.ToString() $strComputer = $system if ($verbose -gt 0) { Write-Output "DisplayName is $strDisplayName" Write-Output "Status is $strStatus" Write-Output "Server is $strComputer" } [array]$obSvcs += New-Object PSObject -Property @{ DisplayName = $strDisplayName Status = $strStatus Server = $strComputer } # $PSObject } # foreeach ($obWinSvc in $obWinSvcs) Clear-Variable -Name ("strDisplayName", "strStatus", "strComputer") } # if ($obWinSvcs) else { [array]$obSvcs += New-Object PSObject -Property @{ DisplayName = "NO ONBASE" Status = "WIN SVC" Server = $system } # $PSObject } #else ($obWinSvcs) } # if (Test-Connection else { [array]$obSvcs += New-Object PSObject -Property @{ DisplayName = "SERVER" Status = "OFFLINE" Server = $system } # $PSObject } # else (Test-Connection $obSvcs | Sort-Object -Property Server, Displayname | Select-Object -Unique -Property Server, DisplayName, Status } #function checkOBWinSvcs -computer localhost function checkOBWinSvcs { param ($computer) $obWinSvcProperty = @() $obWinSvcs = @() $system = $Env:COMPUTERNAME if (Test-Connection -ComputerName $computer -Count 1 -Quiet) { try { [array]$obWinSvcs = Get-CimInstance -ClassName Win32_Service -ComputerName $computer ` -ErrorAction Stop ` -filter "(DisplayName LIKE '%OnBase%') AND startmode != 'Disabled'" | Select-Object -Property DisplayName, StartMode, SystemName, State, StartName, Status, ProcessID, Name, Pathname if($obWinSvcs) { foreach ($obSvc in $obWinSvcs) { $svcDisplayName = $obSvc.DisplayName $svcName = $obSvc.Name $svcStartMode = $obSvc.StartMode.ToString() $svcSystemName = $obSvc.SystemName $svcState = $obSvc.State.ToString() $svcStatus = $obSvc.Status.ToString() $svcProcessID = $obSvc.ProcessID.ToString() $svcPathname = $obSvc.Pathname $svcStartName = $obSvc.StartName $key = "SOFTWARE\WOW6432Node\Hyland\Services\$svcName" $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer) $regkey = $reg.opensubkey($key) $regCmdLine = $regkey.getvalue("CmdLine") $regCmdLine = " " + $regCmdLine $regInstallID = $regkey.getvalue("InstallID") $regRawPath = $regkey.getvalue("RawPath") $regUser = $regkey.getvalue("User") $regKeyPath = "HKLM:SOFTWARE\WOW6432Node\Hyland\Services\" + $svcName $regFullPath = $regRawPath + $regCmdLine [array]$obWinSvcProperty += New-Object PSObject -Property @{ Name = $svcName DisplayName = $svcDisplayName StartMode = $svcStartMode SystemName = $svcSystemName State = $svcState Status = $svcStatus ProcessID = $svcProcessID PathName = $svcPathname Registry = $regKeyPath OnBaseUser = $regUser SvcUser = $svcStartName InstallID = $regInstallID Path = $regRawPath CmdLine = $regCmdLine FullPath = $regFullPath } #$obWinSvcObject = New-Object PSObject Clear-Variable -Name ("svcName", "svcDisplayName", "svcStartMode", "svcSystemName", "svcState", "svcStatus", "svcProcessID", "svcPathname", "svcStartName") Clear-Variable -Name ("regKeyPath", "regUser", "regInstallID", "regRawPath", "regCmdLine", "regFullPath") } #foreach ($obSvc in $obWinSvcs) } else #if ($obWinSvcs) { [array]$obWinSvcProperty += New-Object PSObject -Property @{ Name = "--" DisplayName = "NO OB WIN SVC" StartMode = "--" SystemName = $system State = "--" Status = "--" ProcessID = "--" PathName = "--" Registry = "--" OnBaseUser = "--" SvcUser = "--" InstallID = "--" Path = "--" CmdLine = "--" FullPath = "--" } #$obWinSvcProperty = New-Object PSObject } #else ($obWinSvcs) } #try catch { [array]$obWinSvcProperty += New-Object PSObject -Property @{ Name = "--" DisplayName = "POSSIBLE COM ISSUE" StartMode = "--" SystemName = $system State = "--" Status = "--" ProcessID = "--" PathName = "--" Registry = "--" OnBaseUser = "--" SvcUser = "--" InstallID = "--" Path = "--" CmdLine = "--" FullPath = "--" } #$obWinSvcProperty = New-Object PSObject } #catch } else { [array]$obWinSvcProperty += New-Object PSObject -Property @{ Name = "--" DisplayName = "SERVER OFFLINE" StartMode = "--" SystemName = "--" State = "--" Status = "--" ProcessID = "--" PathName = "--" Registry = "--" OnBaseUser = "--" SvcUser = "--" InstallID = "--" Path = "--" CmdLine = "--" FullPath = "--" } #$obWinSvcProperty = New-Object PSObject } #else (Test-Connection -ComputerName $computer -Count 1 -Quiet) $obWinSvcProperty | Sort-Object -Property SystemName, Status, DisplayName | Select-Object -Property SystemName, DisplayName, StartMode, Status, State, OnBaseUser, ProcessID, Path, CmdLine, InstallID, Name, SvcUser, Registry, PathName, FullPath } #function checkOBWinSvcs -computer localhost
Hi!
Glad to hear the issue has been resolved. Also thanks for sharing your solution.
cheers,
Stefan
hi,
glad to hear its working now!
yes, when some properties cannot be converted, this might be an issue - and is difficult for us to test in our environments.
Regarding the computernames: there is not alot we can do here, since only the network stack can resolve the name and connect.
Since you are using Test-Connection anyway: isnt that preventing this error? I am not sure on which network-layer this "testing" occurs.
best regards,
Michael
John Szefcyk
Hello! I am attempting to execute a Powershell Script using the Powershell Connection in RoyalTS. I am trying to output to Grid and keep getting this error. When I do a TEST on the script in the Powershell Connection properties, I get output.
Current script is below the error.
An error occurred while parsing the response.
Columns do not match
Details:
System.Exception: Columns do not match
at RoyalCommon.Utils.RUDataTable.Merge(RUDataTable otherTable) in File1732:line 92
at RoyalCommon.Server.RoyalServer.SharedUtils.GetMergedResultRUDataTables(RoyalServerResponse response) in File27:line 161
at RoyalCommon.Server.RoyalServer.SharedUtils.GetMergedResultTables(RoyalServerResponse response) in File28:line 26
at RoyalTS.NetworkDictionaryEmulatorService.AttachBuilder(RoyalServerResponse parentCaption)
at RoyalTS.ActivatorProviderToolbarList.InsertGroup(RoyalServerEventArgs parentCaption) in File302:line 859