I tried posting yesterday and it’s apparently still being reviewed by the moderators or something. I think the issue was I tried to post the PS script I was using. But long story short, I still can’t get it to output any data of use. It’s not giving me an error anymore so I THINK it’s running on the remote host now instead of the local but I also don’t know how to know that for sure. Without posting the script, do you know what command I should be using to essentially output the data and then have it add it to the property source?
PS I should have mentioned I’m not a PS guru by any means so I really appreciate any and all help here!
You should be able to post the script.
You should be able to post the script.
It looks like the script came through.
You can add a couple of Write-Host statements to your script to view the value of your variables like so…
# Clears the CLI of any text
Clear-Host
# Clears memory of all previous variables
Remove-Variable * -ErrorAction SilentlyContinue
#------------------------------------------------------------------------------------------------------------
# Initialize Variables
$wmi_pass = '##WMI.PASS##'
$wmi_user = '##WMI.USER##'
$hostname = '##SYSTEM.SYSNAME##'
$collectorName = hostname
write-host \"hostname=\" $hostname;
write-host \"collectorName=\" $collectorName;
# Insert additional variables here
# If the hostname is an IP address query DNS for the FQDN
if ($hostname -match \"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b\") {
$hostname = [System.Net.Dns]::GetHostbyAddress($hostname).HostName
}
## This script block should contain all code that you want to execute remotely on the target host.
$scriptBlock = {
(Get-Command java | Select-Object -ExpandProperty Version).toString()
}
#------------------------------------------------------------------------------------------------------------
try {
#-----Determin the type of query to make-----
# check to see if this is monitoring the localhost collector, as we will not need to authenticate.
if ($hostname -like $collectorName) {
$response = Invoke-Command -ScriptBlock $scriptBlock
}
# are wmi user/pass set -- e.g. are these device props either not substiuted or blank
elseif (([string]::IsNullOrWhiteSpace($wmi_user) -and [string]::IsNullOrWhiteSpace($wmi_pass)) -or (($wmi_user -like '*WMI.USER*') -and ($wmi_pass -like '*WMI.PASS*'))) {
# no
$response = Invoke-Command -ComputerName $hostname -ScriptBlock $scriptBlock
} else {
# yes. convert user/password into a credential string
$remote_pass = ConvertTo-SecureString -String $wmi_pass -AsPlainText -Force;
$remote_credential = New-Object -typename System.Management.Automation.PSCredential -argumentlist $wmi_user, $remote_pass;
$response = Invoke-Command -ComputerName $hostname -Credential $remote_credential -ScriptBlock $scriptBlock
}
exit 0
} catch {
# exit code of non 0 will mean the script failed and not overwrite the instances that have already been found
throw $Error[0].Exception
exit 1
}
","body@stripHtml({\"removeProcessingText\":false,\"removeSpoilerMarkup\":false,\"removeTocMarkup\":false,\"truncateLength\":200})@stringLength":"208","kudosSumWeight":0,"repliesCount":0,"postTime":"2023-07-31T22:00:41.000-07:00","lastPublishTime":"2023-07-31T22:00:41.000-07:00","metrics":{"__typename":"MessageMetrics","views":0},"visibilityScope":"PUBLIC","placeholder":false,"originalMessageForPlaceholder":null,"isEscalated":null,"solution":false,"entityType":"FORUM_REPLY","eventPath":"category:product-hub/community:ajkuw86572board:product-discussions/message:12438/message:12451","replies":{"__typename":"MessageConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[]},"customFields":[],"attachments":{"__typename":"AttachmentConnection","edges":[],"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"readOnly":false,"editFrozen":false,"body@stringLength":"2926","rawBody":"It looks like the script came through.
You can add a couple of Write-Host statements to your script to view the value of your variables like so…
# Clears the CLI of any text
Clear-Host
# Clears memory of all previous variables
Remove-Variable * -ErrorAction SilentlyContinue
#------------------------------------------------------------------------------------------------------------
# Initialize Variables
$wmi_pass = '##WMI.PASS##'
$wmi_user = '##WMI.USER##'
$hostname = '##SYSTEM.SYSNAME##'
$collectorName = hostname
write-host \"hostname=\" $hostname;
write-host \"collectorName=\" $collectorName;
# Insert additional variables here
# If the hostname is an IP address query DNS for the FQDN
if ($hostname -match \"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b\") {
$hostname = [System.Net.Dns]::GetHostbyAddress($hostname).HostName
}
## This script block should contain all code that you want to execute remotely on the target host.
$scriptBlock = {
(Get-Command java | Select-Object -ExpandProperty Version).toString()
}
#------------------------------------------------------------------------------------------------------------
try {
#-----Determin the type of query to make-----
# check to see if this is monitoring the localhost collector, as we will not need to authenticate.
if ($hostname -like $collectorName) {
$response = Invoke-Command -ScriptBlock $scriptBlock
}
# are wmi user/pass set -- e.g. are these device props either not substiuted or blank
elseif (([string]::IsNullOrWhiteSpace($wmi_user) -and [string]::IsNullOrWhiteSpace($wmi_pass)) -or (($wmi_user -like '*WMI.USER*') -and ($wmi_pass -like '*WMI.PASS*'))) {
# no
$response = Invoke-Command -ComputerName $hostname -ScriptBlock $scriptBlock
} else {
# yes. convert user/password into a credential string
$remote_pass = ConvertTo-SecureString -String $wmi_pass -AsPlainText -Force;
$remote_credential = New-Object -typename System.Management.Automation.PSCredential -argumentlist $wmi_user, $remote_pass;
$response = Invoke-Command -ComputerName $hostname -Credential $remote_credential -ScriptBlock $scriptBlock
}
exit 0
} catch {
# exit code of non 0 will mean the script failed and not overwrite the instances that have already been found
throw $Error[0].Exception
exit 1
}
","images":{"__typename":"AssociatedImageConnection","edges":[],"totalCount":0,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"timeToRead":2,"currentRevision":{"__ref":"Revision:revision:12451_1"},"latestVersion":null,"messagePolicies":{"__typename":"MessagePolicies","canModerateSpamMessage":{"__typename":"PolicyResult","failureReason":{"__typename":"FailureReason","message":"error.lithium.policies.feature.moderation_spam.action.moderate_entity.allowed.accessDenied","key":"error.lithium.policies.feature.moderation_spam.action.moderate_entity.allowed.accessDenied","args":[]}}}},"QueryVariables:MessageSolutions":{"__typename":"QueryVariables","id":"MessageSolutions","value":{"first":10,"constraints":{"topicId":{"eq":"message:12438"},"solution":{"eq":true}},"sorts":{"postTime":{"direction":"ASC"}},"useAvatar":true,"useAuthorLogin":true,"useAuthorRank":false,"useBody":true,"useKudosCount":false,"useTimeToRead":false,"useMedia":true,"useRepliesCount":false,"useSearchSnippet":false,"useAcceptedSolutionButton":true,"useSolvedBadge":false,"useAttachments":true,"useTags":false,"useUserHoverCard":false,"useNodeHoverCard":false,"usePreviewSubjectModal":false,"useMessageStatus":false}},"CachedAsset:text:en_US-components/community/NavbarDropdownToggle-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/community/NavbarDropdownToggle-1743036180374","value":{"ariaLabelClosed":"Press the down arrow to open the menu"},"localOverride":false},"CachedAsset:text:en_US-components/messages/EscalatedMessageBanner-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/EscalatedMessageBanner-1743036180374","value":{"escalationMessage":"Escalated to Salesforce by {username} on {date}","viewDetails":"View Details","modalTitle":"Case Details","escalatedBy":"Escalated by: ","escalatedOn":"Escalated on: ","caseNumber":"Case Number: ","status":"Status: ","lastUpdateDate":"Last Update: ","automaticEscalation":"automatic escalation","anonymous":"Anonymous"},"localOverride":false},"CachedAsset:text:en_US-components/users/UserLink-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/users/UserLink-1743036180374","value":{"authorName":"View Profile: {author}","anonymous":"Anonymous"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/users/UserRank-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/users/UserRank-1743036180374","value":{"rankName":"{rankName}","userRank":"Author rank {rankName}"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageTime-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageTime-1743036180374","value":{"postTime":"Published: {time}","lastPublishTime":"Last Update: {time}","conversation.lastPostingActivityTime":"Last posting activity time: {time}","conversation.lastPostTime":"Last post time: {time}","moderationData.rejectTime":"Rejected time: {time}"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageSolvedBadge-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageSolvedBadge-1743036180374","value":{"solved":"Solved"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageSubject-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageSubject-1743036180374","value":{"noSubject":"(no subject)"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageBody-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageBody-1743036180374","value":{"showMessageBody":"Show More","mentionsErrorTitle":"{mentionsType, select, board {Board} user {User} message {Message} other {}} No Longer Available","mentionsErrorMessage":"The {mentionsType} you are trying to view has been removed from the community.","videoProcessing":"Video is being processed. Please try again in a few minutes.","bannerTitle":"Video provider requires cookies to play the video. Accept to continue or {url} it directly on the provider's site.","buttonTitle":"Accept","urlText":"watch"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageCustomFields-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageCustomFields-1743036180374","value":{"CustomField.default.label":"Value of {name}"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageReplyButton-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageReplyButton-1743036180374","value":{"repliesCount":"{count}","title":"Reply","title@board:BLOG@message:root":"Comment","title@board:TKB@message:root":"Comment","title@board:IDEA@message:root":"Comment","title@board:OCCASION@message:root":"Comment"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageSolutionList-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageSolutionList-1743036180374","value":{"emptyDescription":"No has been message solutions yet"},"localOverride":false},"CachedAsset:text:en_US-components/messages/AcceptedSolutionButton-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/AcceptedSolutionButton-1743036180374","value":{"accept":"Mark as Solution","accepted":"Marked as Solution","errorHeader":"Error!","errorAdd":"There was an error marking as solution.","errorRemove":"There was an error unmarking as solution.","solved":"Solved","topicAlreadySolvedErrorTitle":"Solution Already Exists","topicAlreadySolvedErrorDesc":"Refresh the browser to view the existing solution"},"localOverride":false},"CachedAsset:text:en_US-components/messages/MessageView/MessageViewInline-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-components/messages/MessageView/MessageViewInline-1743036180374","value":{"bylineAuthor":"{bylineAuthor}","bylineBoard":"{bylineBoard}","anonymous":"Anonymous","place":"Place {bylineBoard}","gotoParent":"Go to parent {name}"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/common/Pager/PagerLoadMore-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/common/Pager/PagerLoadMore-1743036180374","value":{"loadMore":"Show More"},"localOverride":false},"Revision:revision:12448_1":{"__typename":"Revision","id":"revision:12448_1","lastEditTime":"2023-07-18T12:04:27.000-07:00"},"Revision:revision:12451_1":{"__typename":"Revision","id":"revision:12451_1","lastEditTime":"2023-07-31T22:00:41.000-07:00"},"User:user:457":{"__typename":"User","id":"user:457","uid":457,"login":"mnagel","biography":null,"registrationData":{"__typename":"RegistrationData","status":null,"registrationTime":"2016-05-17T11:35:18.000-07:00"},"deleted":false,"email":"","avatar":{"__typename":"UserAvatar","url":"https://community.logicmonitor.com/legacyfs/online/avatars/464420b7fbf4edb9659689e030d7e07a.jpg"},"entityType":"USER","eventPath":"community:ajkuw86572/user:457","rank":{"__ref":"Rank:rank:15"}},"ModerationData:moderation_data:12439":{"__typename":"ModerationData","id":"moderation_data:12439","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"AcceptedSolutionMessage:message:12439":{"__typename":"AcceptedSolutionMessage","author":{"__ref":"User:user:457"},"id":"message:12439","revisionNum":1,"uid":12439,"depth":1,"hasGivenKudo":false,"subscribed":false,"board":{"__ref":"Forum:board:product-discussions"},"parent":{"__ref":"ForumTopicMessage:message:12438"},"conversation":{"__ref":"Conversation:conversation:12438"},"subject":"Re: Monitor version of Java","moderationData":{"__ref":"ModerationData:moderation_data:12439"},"body":"The Powershell command you need is:
(Get-Command java | Select-Object -ExpandProperty Version).toString()
If you set that up in a PropertySource, then you could write a datasource against that property with a datapoint that checks the version string against your required value.
","body@stripHtml({\"removeProcessingText\":true,\"removeSpoilerMarkup\":true,\"removeTocMarkup\":true,\"truncateLength\":200})@stringLength":"203","postTime":"2023-04-26T11:33:40.000-07:00","lastPublishTime":"2023-04-26T11:33:40.000-07:00","images":{"__typename":"AssociatedImageConnection","edges":[],"totalCount":0,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"attachments":{"__typename":"AttachmentConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[]},"solution":true,"metrics":{"__typename":"MessageMetrics","views":140},"placeholder":false,"originalMessageForPlaceholder":null,"videos":{"__typename":"VideoConnection","edges":[],"totalCount":0,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"isEscalated":null,"entityType":"FORUM_REPLY","eventPath":"category:product-hub/community:ajkuw86572board:product-discussions/message:12438/message:12439","customFields":[],"readOnly":false,"editFrozen":false,"body@stringLength":"297","rawBody":"The Powershell command you need is:
(Get-Command java | Select-Object -ExpandProperty Version).toString()
If you set that up in a PropertySource, then you could write a datasource against that property with a datapoint that checks the version string against your required value.
","kudosSumWeight":16,"repliesCount":0,"timeToRead":1,"currentRevision":{"__ref":"Revision:revision:12439_1"},"latestVersion":null,"visibilityScope":"PUBLIC","messagePolicies":{"__typename":"MessagePolicies","canModerateSpamMessage":{"__typename":"PolicyResult","failureReason":{"__typename":"FailureReason","message":"error.lithium.policies.feature.moderation_spam.action.moderate_entity.allowed.accessDenied","key":"error.lithium.policies.feature.moderation_spam.action.moderate_entity.allowed.accessDenied","args":[]}}}},"Revision:revision:12449_1":{"__typename":"Revision","id":"revision:12449_1","lastEditTime":"2023-07-19T05:19:19.000-07:00"},"CachedAsset:text:en_US-shared/client/components/users/UserAvatar-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/users/UserAvatar-1743036180374","value":{"altText":"{login}'s avatar","altTextGeneric":"User's avatar"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/ranks/UserRankLabel-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/ranks/UserRankLabel-1743036180374","value":{"altTitle":"Icon for {rankName} rank"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/nodes/NodeIcon-1743036180374":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/nodes/NodeIcon-1743036180374","value":{"contentType":"Content Type {style, select, FORUM {Forum} BLOG {Blog} TKB {Knowledge Base} IDEA {Ideas} OCCASION {Events} other {}} icon"},"localOverride":false},"AssociatedImage:{\"url\":\"https://community.logicmonitor.com/t5/s/ajkuw86572/images/cmstMTUtQ0FvYjd5\"}":{"__typename":"AssociatedImage","url":"https://community.logicmonitor.com/t5/s/ajkuw86572/images/cmstMTUtQ0FvYjd5","height":220,"width":1140,"mimeType":"image/png"},"Rank:rank:15":{"__typename":"Rank","id":"rank:15","position":16,"name":"Professor","color":"333333","icon":{"__ref":"AssociatedImage:{\"url\":\"https://community.logicmonitor.com/t5/s/ajkuw86572/images/cmstMTUtQ0FvYjd5\"}"},"rankStyle":"TEXT"},"Revision:revision:12439_1":{"__typename":"Revision","id":"revision:12439_1","lastEditTime":"2023-04-26T11:33:40.000-07:00"}}}},"page":"/forums/ForumMessagePage/ForumMessagePage","query":{"after":"MjUuMnwyLjF8b3wxMHwxNDowLDM5OjF8MTA","boardId":"product-discussions","messageSubject":"monitor-version-of-java","messageId":"12438"},"buildId":"q_bLpq2mflH0BeZigxpj6","runtimeConfig":{"buildInformationVisible":false,"logLevelApp":"info","logLevelMetrics":"info","openTelemetryClientEnabled":false,"openTelemetryConfigName":"logicmonitor","openTelemetryServiceVersion":"25.2.0","openTelemetryUniverse":"prod","openTelemetryCollector":"http://localhost:4318","openTelemetryRouteChangeAllowedTime":"5000","apolloDevToolsEnabled":false,"inboxMuteWipFeatureEnabled":false},"isFallback":false,"isExperimentalCompile":false,"dynamicIds":["./components/seo/QAPageSchema/QAPageSchema.tsx","./components/community/Navbar/NavbarWidget.tsx","./components/community/Breadcrumb/BreadcrumbWidget.tsx","./components/messages/TopicWithThreadedReplyListWidget/TopicWithThreadedReplyListWidget.tsx","./components/messages/RelatedContentWidget/RelatedContentWidget.tsx","./components/messages/MessageListForNodeByRecentActivityWidget/MessageListForNodeByRecentActivityWidget.tsx","./components/community/FooterWidget/FooterWidget.tsx","./components/messages/MessageView/MessageViewStandard/MessageViewStandard.tsx","./components/messages/ThreadedReplyList/ThreadedReplyList.tsx","./components/community/FooterWidgetHelpLink/FooterWidgetHelpLink.tsx","./components/community/KhorosLogo/KhorosLogo.tsx","../shared/client/components/common/List/UnstyledList/UnstyledList.tsx","./components/messages/MessageView/MessageView.tsx","./components/messages/MessageView/MessageViewInline/MessageViewInline.tsx","../shared/client/components/common/List/ListGroup/ListGroup.tsx","../shared/client/components/common/Pager/PagerLoadMore/PagerLoadMore.tsx"],"appGip":true,"scriptLoader":[]}