h41msh1c0r
Goto Top

Powershell Get-Services im Invoke Command

Aloa,

Nicht mehr lang.

$HtServices = @{
    RS= $null
    RT= $null 
    RR= $null
  }

$CustomObjectServices = [pscustomobject]$HtServices

function get-data{
	[CmdletBinding()]
	[OutputType([System.Object])]
	param(
		[Parameter(Position=0, Mandatory=$true)]
		[ValidateNotNullOrEmpty()]
		[System.String]
		$ServerName,

		[Parameter(Position=1, Mandatory=$true)]
		[ValidateNotNullOrEmpty()]
		[System.Object]
		$ObjectListServices

	)
        $result = Invoke-Command -ComputerName $Server -ScriptBlock {param($ObjectListServices) 
            
         $ObjectListServices | %{
                $Ret = Get-Service -Name $_.Name -ErrorAction SilentlyContinue  
                if ( ! $Ret ) { $_.Value = "NA" } else { $_.Value = $Ret.Status  }  
          }
          Return $ObjectListServices
        } -ArgumentList $ObjectListServices
        return $result
}

get-data -ServerName $Server -ObjectListServices $CustomObjectServices

So richtig mag das noch nicht.

Der "-Name" ist das Property und das Ergebnis soll in das Value vom Property, bisher bekomm ich das nicht gefüllt.


VG

Content-Key: 359491

Url: https://administrator.de/contentid/359491

Printed on: April 25, 2024 at 21:04 o'clock

Mitglied: 135051
135051 Dec 29, 2017 updated at 21:11:10 (UTC)
Goto Top
Du hast aus deiner Hashtable ein CustomObject gemacht und da gibt es kein $_.Name oder $_.Value mehr, nur noch deine Eigenschaften RS,RT, und RR
Schon am bisl spät was face-smile. Schluck Kaffee dann geht's wieder face-wink

Gruß @135051
Member: H41mSh1C0R
H41mSh1C0R Jan 03, 2018 at 10:36:46 (UTC)
Goto Top
Auch wenn 135051 bereits wieder abgemeldet ist vielleicht liest hier das ja jemand.

   $result = Invoke-Command -ComputerName $Server -ScriptBlock {param($ObjectListServices)

            New-Object PSObject -Property @{
                Computer = hostname
                IP = ([system.net.dns]::GetHostEntry("$serv")).AddressList.IPAddressTostring  
                Services = Get-Service -ErrorAction SilentlyContinue | ? {$_.Name -in $ObjectListServices}
                RebootPending = Get-ItemProperty "HKLM:\SOFTWARE­\Microsoft­\Windows­\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired"  -ErrorAction SilentlyContinue  
            } 
           
        }  

Jetzt wird zwar das alles zurückgeliefert was ich gern hätte. Mit Get-Service allerdings mehr als gewünscht.
Ich würde nur die Dienste haben wollen die in $ObjectListServices stehen.

Mit
                Services = Get-Service -ErrorAction SilentlyContinue | ? {$_.Name -in $ObjectListServices}
kommt allerdings nichts zurück.

;(

Hat einer eine Idee?

VG