Question 2011 Scripting Games : Advanced Event 4

Plus d'informations
il y a 14 ans 11 mois #9626 par Matthew BETTON
Bonsoir,

Ci-après le script que j'ai posté lors des Scripting Games 2011, dans le cadre de l'Advanced Event 4.

Le scénario était le suivant :

You are the network administrator for a large company with multiple locations around the world. Your performance team has expressed concern with the large amount of memory that is consumed by one particular instance of the SvcHost process. To investigate this process, the team lead has requested that you write a Windows PowerShell script that will list each instance of the SvcHost process, the amount of committed memory, the number of page faults, and the command line that launched each SvcHost process. In addition, the lead requires that the script list each service that is running inside each instance of the SvcHost process. An appropriate output from the script is shown in the following image.



Mon script (une solution) :


[code:1]#
# 2011 Scripting Games : Advanced Event 4
# Script : Get-SvcHostsStatus.ps1
# Author : Matthew BETTON (France / Basse-Normandie / Manche (50))
# Date : 04/07/2011
# Synopsis : Use PowerShell to Investigate the SvcHost Process
#

param(
[Parameter(Mandatory=$true)]
[String]$ComputerName,
[string]$ExportCSV
)

# Get the svchost processes list (WMI)
$SvcHostProcess = Get-WmiObject -Class Win32_Process -ComputerName $ComputerName -Filter \"Name = 'svchost.exe'\"

$Tab = $null
$Tab = @()

foreach($Process in $SvcHostProcess){

# Get the service(s) that is (are) running inside the instance of the current svchost process
$svc = get-wmiobject win32_service -ComputerName $ComputerName -filter \"processid=$($Process.ProcessId)\"

foreach($Service in $svc){
# Create a new object
$ProcObj = New-Object PSObject
# Add new properties to the object
$ProcObj | Add-Member -MemberType NoteProperty -Name \"ProcessID\" -Value $Process.ProcessID -PassThru `
| Add-Member -MemberType NoteProperty -Name \"PageFaults\" -Value $Process.PageFaults -PassThru `
| Add-Member -MemberType NoteProperty -Name \"CommitedMemory\" -Value $Process.VirtualSize -PassThru `
| Add-Member -MemberType NoteProperty -Name \"CommandLine\" -Value $Process.CommandLine -PassThru `
| Add-Member -MemberType NoteProperty -Name \"StartMode\" -Value $Service.StartMode -PassThru `
| Add-Member -MemberType NoteProperty -Name \"State\" -Value $Service.State -PassThru `
| Add-Member -MemberType NoteProperty -Name \"ServiceName\" -Value $Service.Name
# Commited Memory

# Add the object to the collection
$Tab += $ProcObj

}
}

# If '-ExportCSV' parameter is used
if($ExportCSV){
# Export data to the specified CSV file
$Tab | Export-Csv -NoTypeInformation -Path $ExportCSV
}
else{
# Writte objects to the output
$Tab
}[/code:1]

Pour les personnes que cela intéresse, voici le lien vers une solution d'un expert .

Toutes les remarques seront les bienvenues ! ;)

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 19 heures 1 minute #54722 par Miguel
Hey, après une longue journée je voulais juste me détendre et un ami m’a parlé de quelque chose qui a aussi des avantages pour les joueurs en France alors j’ai essayé book of dead slot et au début j’ai enchaîné quelques pertes, ce qui m’a presque fait arrêter, mais j’ai pris un petit risque en plus et une belle victoire est tombée. J’aime bien le fait qu’on garde le contrôle et que le rythme reste calme, parfait pour de courtes sessions.

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.036 secondes
Propulsé par Kunena