New MPToolPSDiscovery - AndreasSobczyk/MPTool GitHub Wiki
#New-MPToolPSDiscovery This function will create a new Powershell discovery from a few simple input parameters and script with a array object that contains the discovery class properties. Will also verify or add all need management pack references.
###Parameters
- ManagementServerFQDN [string] β FQDN of the management server to connect.
Example - scom01.contoso.com - ManagementPackName [string] β Name of the management pack.
Example - "Contoso.VMSwitch.Discovery" - DiscoveryName [string] β Name of the discovery.
Example - "Contoso.SCVMM.VMSwitch.Discovery" - DiscoveryDisplayName [string] β (Optional) Display name of the discovery.
Example - "Contoso SCVMM VMSwitch Discovery" - DiscoveryClassName [string] β Name of the class to discover. This is the class to discover.
Example - "Contoso.SCVMM.VMSwitch" - TargetClassName [string] β Target class for the discovery to run on.
Example - "Microsoft.SystemCenter.VirtualMachineManager.VMMManagementServer" - TargetClassMPName [string] β (Optional) Name of the target class management pack.
Example - "Microsoft.SystemCenter.VirtualMachineManager.Library" - TargetClassMPAlias [string] β (Optional) Alias of the target class management pack.
Example - "VMMLibrary" - IntervalSeconds [int] β Interval in seconds for the discovery to run.
Example - 86000 - TimeoutSeconds [int] β Timeout in seconds for the script to timeout.
Example - 45 - Script [string] β PowerShell script for the discovery. This script must create a array object called $DiscoveryObjects with properties matching the properties of the discovery class.
Example -
@'
$DiscoveryObjects = @()
Get-SCVMMServer $env:COMPUTERNAME | Out-Null
$VMSwitches = Get-SCVirtualNetwork | select Name,VMHost
foreach($VMSwitch in $VMSwitches){
$ClassProperties = @{} | select DeviceID,Switchname,VMHost
$ClassProperties.DeviceID = VMSwitch.VMHost.ToString()+","+$VMSwitch.Name.ToString()
$ClassProperties.Switchname = $VMSwitch.Name.ToString()
$ClassProperties.VMHost = $VMSwitch.VMHost.ToString()
$DiscoveryObjects += $ClassProperties
}
'@
- ScriptParameters [array] β (Optional) Script input parameters is used to get property values from the target class or the target classβs host. The parameters name must match a property on the target class or itβs host.
Example - @("Version") - Enabled [boolean] β (Optional) If the discovery should be enabled - $true/$false β Default: $false.
###Example Creates a new Powershell Discovery called Contoso.SCVMM.VMSwitch.Discovery for the class Contoso.SCVMM.VMSwitch, this class contains properties DeviceID Switchname and VMHost. The discovery will run on all instances of the class, "Microsoft.SystemCenter.VirtualMachineManager.VMMManagementServer", and discovery all the instances of the Contoso.SCVMM.VMSwitch on the VMM server.
New-MPToolPSDiscovery -ManagementServerFQDN scom01.contoso.com `
-ManagementPackName "Contoso.VMSwitch.Discovery" `
-DiscoveryName "Contoso.SCVMM.VMSwitch.Discovery" `
-DiscoveryDisplayName "Contoso SCVMM VMSwitch Discovery" `
-DiscoveryClassName "Contoso.SCVMM.VMSwitch" `
-TargetClassName "Microsoft.SystemCenter.VirtualMachineManager.VMMManagementServer" `
-IntervalSeconds 300 `
-TimeoutSeconds 45 `
-Script @'
$DiscoveryObjects = @()
Get-SCVMMServer $env:COMPUTERNAME | Out-Null
$VMSwitches = Get-SCVirtualNetwork | select Name,VMHost
foreach($VMSwitch in $VMSwitches){
$ClassProperties = @{} | select DeviceID,Switchname,VMHost
$ClassProperties.DeviceID = $VMSwitch.VMHost.ToString()+","+$VMSwitch.Name.ToString()
$ClassProperties.Switchname = $VMSwitch.Name.ToString()
$ClassProperties.VMHost = $VMSwitch.VMHost.ToString()
$DiscoveryObjects += $ClassProperties
}
'@ `
-Enabled $true