Powershell Script to fetch netback client and SMTP relay - powershell

Is there anyway to fetch value for "netbackup client version" and "whether the server requires SMTP relay or not" using powershell script? Below script I used to get the citrix version in the windows server not sure how to get the other values.
powershell "$Citrix=(Get-WmiObject -Class Win32_Product | Sort-object Name | select Name, version | Where { $_.Name -match 'Citrix'}).version -join ',';Write-Host "Citrix = $Citrix";' '"

Dependent services can be looked up with Get-Service cmdlet. I don't have Netback, so let's use Sql Server as an example. The Agent depends on Sql Server like so,
Get-Service -Name 'SQLAgent$SQLI001' -RequiredServices
Status Name DisplayName
------ ---- -----------
Stopped MSSQL$SQLI001 SQL Server (SQLI001)
As for how to get the software version, see if the binary contains the version. This approach requires you to know the binary path. Like so,
(Get-ChildItem E:\MSSQL12.SQLI001\MSSQL\Binn\SQLAGENT.EXE).VersionInfo | Select-Object -Property ProductVersion,FileVersion
ProductVersion FileVersion
-------------- -----------
12.0.5207.0 2014.0120.5207.00 ((SQL14_PCU_main).170703-0132 )

Related

Using PowerShell Invoke-Command not providing same IIS info when commands ran locally trying to get SSLBinding

I can't for the life of me figure out how to get my code to work remotely to show the same information it's showing when ran locally.
For example, if I run the command locally on a web server:
Get-ChildItem IIS:SSLBindings
I get the following results:
But if I run the command remotely using the following code:
Invoke-command -computer $Computer { Import-Module WebAdministration; Get-Childitem -Path IIS:\SslBindings }
I get this result:
I don't understand why the Sites info is blank, or just showing '...'.
I've tried all sorts of different variations/scriptblocks, but the results are always the same.
Anyone have any idea as to what I'm doing wrong or how I can remotely pull this information correctly?
I feel like there may be a better way to do this because this feels a bit clunky, but regardless, it works...
Here's the command I am using to gather this info remotely:
$SSLCertInUseInfo = Invoke-command -computer $Computer {
Import-Module WebAdministration; Get-Childitem -Path IIS:\SslBindings | Select IPAddress, Host, Port, Store,
#{ Name = 'Site'; Expression = { $_ | select -property Sites -expandproperty Sites | Select-Object -ExpandProperty "Value" } }
} | Select -Property * -ExcludeProperty PSComputerName, RunSpaceID, PSShowComputerName
The result is:
Why this particular property is an issue: The cause for this is how the value for Sites is generated. This particular property happens to be a "ScriptProperty," which means it's pulled by a script defined in the WebAdministration module. That script is executed behind the scenes transparently. Unfortunately, ScriptProperties often don't survive the deserialization process when accessed through PSRemoting.
So, how do you find out if the property is a ScriptProperty? Check the member definitions by piping your command to Get-Member.
When run locally, you can see that the Sites member type is a ScriptProperty and the definition shows the start of the script it runs to fetch the data.
PS C:\> Get-Childitem -Path IIS:\SslBindings | Get-Member Sites
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Sites ScriptProperty System.Object Sites {get=$ip = [string]::empty...
When run remotely, you can see the type changes to one prefixed with "Deserialized," the member type is now a NoteProperty, and the definition changes to a string with no value.
PS C:\> Invoke-Command -ComputerName $Computer { Import-Module WebAdministration;Get-Childitem -Path IIS:\SslBindings } | Get-Member Sites
TypeName: Deserialized.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Sites NoteProperty System.String Sites=
How to solve the problem: The easiest way to get the desired value is to use calculated properties to convert the output to something that can be sent back. Similar to this answer, but a little more compact:
Invoke-Command -ComputerName $Computer {
Import-Module WebAdministration; Get-Childitem -Path IIS:\SslBindings |
Select-Object IPAddress, Port, Host, Store, #{Name="Sites"; Expression={($_).Sites.Value}} } |
Select-Object * -ExcludeProperty PSComputerName, RunSpaceID, PSShowComputerName
Output:
IPAddress : ::
Port : 443
Host :
Store : MY
Sites :
IPAddress : 0.0.0.0
Port : 443
Host :
Store : My
Sites : Default Web Site

Get-WmiObject to combine to outputs

I was executing below script to obtain the server patch version of Skype for business servers.
I need the output as server patch name, version and computername.
$x = Get-Content "E:\temp\servers.txt"
foreach ($y in $x)
{
Invoke-Command -ComputerName $y -scriptblock {Get-WmiObject -query ‘select name, version from win32_product’ | where {$_.name -like “*Skype for Business server 2015, core*”}} | Select-object name, Version, #{Name='ComputerName';Expression={$y}} | ft -AutoSize
}
But I am receiving output as below
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx
I don't need my header tiles in every line of output. Any suggestions?
You are getting headers for each computer because the select
statement is inside the foreach loop.
Invoke-command accepts multiple
computers so you dont need a foreach loop.
use server-side filtering
where possible.
$x = Get-Content "E:\temp\servers.txt"
Invoke-Command -ComputerName $x -scriptblock {Get-WmiObject -query "select name, version from win32_product where name like 'Skype for Business server 2015, Core%'"} |
Select-object PSComputerName,name, Version
For future:
Use Get-CimInstance because Get-wmiobject is deprecated.
Do not use win32_product because it can potentially lead to msi corruption. Use
the registry instead.
https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/find-installed-software

SCOM 2012 Windows Service Monitoring Target object

How can I find name of group targeted a windows service monitor which created with template using Powershell?
I mean, I created a monitor in scom using template, I am checking a service. I targeted the monitor to a group. I want to find group name with Powershell.
I wants to get target information on windows service template. How can I get this using Powershell?
To retrieve the target ID for 'All Windows Computers' , execute $targetID = Get-SCOMClassInstance -Class (Get-SCClass | Where-Object DisplayName -Like 'All Windows Computers') | Select ManagementPackClassIds.
Then use the target ID to query ' Get-SCOMMonitor | Select-Object -First 1 | where-object DisplayName -eq 'Queries With High Fetches' | where-object Target -like 'ManagementPackElementUniqueIdentifier=$targetID*'` and see what you get. This is just how you could go about it. Please note that you might have to perform the some string interpolation to get this to work with $targetID.

How to check if a particular service is running in a remote computer using PowerShell

I have 3 servers, running 3 services:
SERVER-A running serv1.exe service
SERVER-B running serv2.exe service
SERVER-C running serv3.exe service
Using PowerShell how can I query each service to check if they are running and output the information to a text file?
If they all have the same name or display name you can do it in one command. If not you need to run 3 commands.
If all have the same name or display name:
Get-Service -ComputerName server-a, server-b, server-c -Name MyService |
Select Name, MachineName, Status
If they have different names or display names:
I would do this --
#{
'server-a' = 'service-a'
'server-b' = 'service-b'
'server-c' = 'service-c'
}.GetEnumerator() | ForEach-Object {
Get-Service -ComputerName $_.Name -Name $_.Value
} | Select Name, MachineName, Status
To output to a text file use ... | Set-Content ~\Documents\Service_Status.txt where ... is one of the above.
Note - your account will need to have privileges to query the remote machines.
There are several ways to achieve this. I am using a hash of the values since you mentioned that the server to service mapping is always one to one.
$svrHash = #{"SERVER-01"="winmgmt";"SERVER-02"="Wecsvc"}
$svrHash.Keys
| ForEach-Object {Get-Process -ComputerName $_ -Name $svrHash[$_] -Ea SilentlyContinue}
| Select ProcessName
| Out-File C:\Scripts\test.txt
You need to use the service name and not the .exe name.

Rename Services & Application in Failover Cluster Manager Using Powershell

PS C:\Users\sup> Get-ClusterGroup | Where-Object {$_.name -ilike "*scvmm*"}
Name Owner State
---- --------- -----
scvmm..rtrtry.exported n01 Offline
scvmm..rtrtry566.exported n02 Offline
Hi All, i wanted to rename the services & application in Failover cluster manager which have the words scvmm & exported in it using powershell, for example the above names should be changed to ..rtrtry. & ..rtrtry566., could some one help me out?
You can get the objects you want with a regex match and set the name property:
get-clustergroup |
where {$_.Name -match "scvmm\.(.*)\.exported"} |
foreach {$_.Name = $matches[1]}