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.
Related
I have been looking at all the PowerShell commands like Select-WebConfiguration, Get-WmiObject, Get-IISAppPool to generate a list of the enabled App Pool authentication settings for all the app pools on my servers. We have like 10 servers and a dozen+ app pools on each and want to find a quick way to check settings. Checked a lot on the web and haven't been able to find a command to generate a nice neat listing.
If you want to get the iis application pool identity then you could try the below command:
Import-Module WebAdministration;Get-ChildItem -Path IIS:\AppPools\ |
Select-Object name, #{e={$_.processModel.username};l="username"}, <##{e={$_.processModel.password};l="password"}, #> #{e={$_.processModel.identityType};l="identityType"} |
format-table -AutoSize
I was able to piece this together below and it seemed to work. Once last thing I am trying to figure out is how to use this same command to query remote servers
Get-WebConfiguration system.webServer/security/authentication/* -Recurse | where {$_.enabled -eq $true} | Sort-Object location,itemxpath | Select location,itemxpath,enabled | format-table -AutoSize
I found out that to run this command on another machine you use the command enter-pssession and the server name. It does not provide any switches that allow you to run them on another server.
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 )
If a computer has multiple gateways, how can I determine which is the default gateway using the PowerShell?
If you're on PowerShell v3, you can use Get-NetIPConfiguration e.g.:
Get-NetIPConfiguration | Foreach IPv4DefaultGateway
I think this will be more cross platform:
Get-NetRoute |
where {$_.DestinationPrefix -eq '0.0.0.0/0'} |
select { $_.NextHop }
You need to know which of the multiple gateways are used? If so. From what I remember, when multiple gateways are available the gateway with the lowest metric("cost" based on link speed) is used. To get this, run the following command:
Get-WmiObject -Class Win32_IP4RouteTable |
where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} |
Sort-Object metric1 | select nexthop, metric1, interfaceindex
if there are multiple default gateways with the same cost, I think it's decided using the binding order of the network adapters. The only way I know to get this is using GUI and registry. To include binding order you could save the output of the script over, get the settingsid from Win32_networkadapterconfiguration (identify using interfaceindex), and read the registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage\Bind. This key lists the binding order it seems, and the settingsid you get from win32_networkadapterconfiguration is the GUID they identify the device with. Then sort the gateways with equal metrics using their order in the Bind reg.key and you got your answer.
Explained in: Technet Social - NIC adapter binding
I found it as the below which lists all active gateways, correct me if I am wrong
(Get-wmiObject Win32_networkAdapterConfiguration | ?{$_.IPEnabled}).DefaultIPGateway
Use the WMI queries to pull the data that you're looking for. Below is a fairly simple example to pull the default gateway for a device specified in the first line variable. This will query the device for network adapters and display the found information (for each adapter) to the console window - pulls adapter index, adapter description, and default gateway
Shouldn't take much to expand this to process multiple devices, or process based on a list fed via an input file.
$computer = $env:COMPUTERNAME
Get-WmiObject win32_networkAdapterConfiguration -ComputerName $computer |
Select index,description,defaultipgateway |
Format-Table -AutoSize
$ActiveNet = Get-NetAdapter –Physical |Where-Object {$_.status -eq "Up"} | select name
$Network = Get-NetIPAddress |Where-Object EnabledDefault -EQ 2 | Where-Object InterfaceAlias -EQ $ActiveNet.name | Where-Object IPv4Address -NE $null | select *
$DefautGateway = Get-NetRoute -InterfaceIndex $Network.InterfaceIndex -DestinationPrefix "0.0.0.0/0" | select NextHop
$DefautGateway.NextHop
If a computer has multiple gateways, how can I determine which is the default gateway using the PowerShell?
If you're on PowerShell v3, you can use Get-NetIPConfiguration e.g.:
Get-NetIPConfiguration | Foreach IPv4DefaultGateway
I think this will be more cross platform:
Get-NetRoute |
where {$_.DestinationPrefix -eq '0.0.0.0/0'} |
select { $_.NextHop }
You need to know which of the multiple gateways are used? If so. From what I remember, when multiple gateways are available the gateway with the lowest metric("cost" based on link speed) is used. To get this, run the following command:
Get-WmiObject -Class Win32_IP4RouteTable |
where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} |
Sort-Object metric1 | select nexthop, metric1, interfaceindex
if there are multiple default gateways with the same cost, I think it's decided using the binding order of the network adapters. The only way I know to get this is using GUI and registry. To include binding order you could save the output of the script over, get the settingsid from Win32_networkadapterconfiguration (identify using interfaceindex), and read the registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage\Bind. This key lists the binding order it seems, and the settingsid you get from win32_networkadapterconfiguration is the GUID they identify the device with. Then sort the gateways with equal metrics using their order in the Bind reg.key and you got your answer.
Explained in: Technet Social - NIC adapter binding
I found it as the below which lists all active gateways, correct me if I am wrong
(Get-wmiObject Win32_networkAdapterConfiguration | ?{$_.IPEnabled}).DefaultIPGateway
Use the WMI queries to pull the data that you're looking for. Below is a fairly simple example to pull the default gateway for a device specified in the first line variable. This will query the device for network adapters and display the found information (for each adapter) to the console window - pulls adapter index, adapter description, and default gateway
Shouldn't take much to expand this to process multiple devices, or process based on a list fed via an input file.
$computer = $env:COMPUTERNAME
Get-WmiObject win32_networkAdapterConfiguration -ComputerName $computer |
Select index,description,defaultipgateway |
Format-Table -AutoSize
$ActiveNet = Get-NetAdapter –Physical |Where-Object {$_.status -eq "Up"} | select name
$Network = Get-NetIPAddress |Where-Object EnabledDefault -EQ 2 | Where-Object InterfaceAlias -EQ $ActiveNet.name | Where-Object IPv4Address -NE $null | select *
$DefautGateway = Get-NetRoute -InterfaceIndex $Network.InterfaceIndex -DestinationPrefix "0.0.0.0/0" | select NextHop
$DefautGateway.NextHop
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]}