Question Problèmes de Workflow

Plus d'informations
il y a 12 ans 11 mois #14430 par sebastien
Problèmes de Workflow a été créé par sebastien
Bonjour à tous,

Étant passé à la V3 de Powershell, je tente de profiter des nouveautés et celle qui à tout de suite attiré mon attention, c'est le 'Workflow'. Après lecture des docs et compulsion de quelques scripts, je me suis lancé dans la migration d'un de mes scripts V2 que j'utilise en permanence. Malheureusement, ce n'est pas aussi simple qu'escompté.
Il semble que j'utilise mal le InlineScript {}. Vous trouverez ci-dessous le script V2 fonctionnel et le V3 quivapa. Pour expliquer rapidement ce qu'ils font :
C'est une boucle infinie. Le premier Get-HpcNode renvoie une série de serveur sur lesquels je vérifie l'état d'une application/service. Le deuxième Get-HpcNode me permet d'avoir un affichage de plusieurs paramètres des serveurs. J'ai essayé d’aérer le code au maximum pour une meilleure visibilité. Je cherche donc à comprendre ce qui ne va pas dans mon utilisation des workflows. De plus, si en parcourant le script, vous voyez des optimisations flagrantes que je pourrais appliquer, n'hésitez pas à me le remonter.

[code:1]
#CODE V2 OK
Add-PSSnapin -name Microsoft.HPC
if ((Get-PSSnapin \"Microsoft.HPC\") -notlike \"Microsoft.HPC\") {Add-PSSnapin -name Microsoft.HPC}

cls
Do {

Get-HpcNode -Scheduler XXX117 | Sort-Object \"NetBiosName\" | %{

if ((get-Process -computername $_.netbiosname WSCommCntr3 -ErrorAction \"SilentlyContinue\").count -gt 1)
{Invoke-Command -ComputerName $_.NetbiosName { Get-Process WSCommCntr3,3dsmax,maxadapter.adp | Stop-Process -Force } }

if (!(($_.netbiosname -eq \"XXX158\") -or ($_.netbiosname -eq \"XXX159\") -or ($_.netbiosname -eq \"XXX163\") -or ($_.netbiosname -eq \"XXX164\"))){

If ((([math]::round(((Get-WmiObject -computername $_.netbiosname -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2)) -le 1) -and ((Get-Service -ComputerName $_.netbiosname -Name \"BACKBURNER_SRV_200\" -ErrorAction \"SilentlyContinue\").status -eq \"Running\"))
{ invoke-command -computername $_.netbiosname {Stop-Service -Name \"BACKBURNER_SRV_200\" } }

elseif ((([math]::round(((Get-WmiObject -computername $_.netbiosname -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2)) -gt 4) -and ((Get-Service -ComputerName $_.netbiosname -Name \"BACKBURNER_SRV_200\" -ErrorAction \"SilentlyContinue\").status -eq \"Stopped\"))
{ invoke-command -computername $_.netbiosname {Start-Service -Name \"BACKBURNER_SRV_200\" } }


If ((Get-Service -ComputerName $_.netbiosname -Name \"BACKBURNER_SRV_200\" -ErrorAction \"SilentlyContinue\").status -eq \"Running\"){
If (!((invoke-command -computername $_.netbiosname {((gps serversvc).priorityclass)}) -eq \"Idle\")){
invoke-command -computername $_.netbiosname {(gps serversvc).priorityclass = \"Idle\"}}}

}}


Clear-Host
get-date | out-default
Write-Output \" \"

Get-HpcNode -Scheduler XXX117 | Sort-Object \"NetBiosName\" | Format-table -property `
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"NetBiosName\";Expression={$_.netbiosname}; alignment=\"center\"},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"freemem\";Expression={([math]::round(((Get-WmiObject -computername $_.netbiosname -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2))}; alignment=\"center\"},`
@{label=\"freedisk\";Expression={([math]::round(((get-wmiobject -computer $_.netbiosname win32_logicaldisk -Filter \"drivetype=3\").freespace/1GB),2))}; alignment=\"center\"},`
@{label=\"NodeState\";Expression={$_.NodeState}; alignment=\"center\"},`
@{label=\"Health\";Expression={$_.NodeHealth}; alignment=\"center\"},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"Orcaflex\"; Expression={(Get-Service -ComputerName $_.netbiosname -Name \"DOFClientService\").status};width=8},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"3DSMax service & priority\"; Expression={(Get-Service -ComputerName $_.netbiosname -Name \"BACKBURNER_SRV_200\").status;invoke-command -computername $_.netbiosname {((gps serversvc).priorityclass)} }},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"Groups\";Expression={$_.Groups}; alignment=\"left\"},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"} -AutoSize

job list /user:* /state:Running

Start-Sleep 300
Clear-host
} While ($true)
[/code:1]

[code:1]
#CODE V3 NOK
Add-PSSnapin -name Microsoft.HPC
$env:ccp_scheduler = \"XXX117\"
cls

Workflow check_Backburner
{
param ([array]$nodes)

ForEach -Parallel ($node in $nodes)
{
if ((get-Process -computername $node WSCommCntr3 -ErrorAction \"SilentlyContinue\").count -gt 1)
{
InlineScript {Invoke-Command -ComputerName $node {Get-Process WSCommCntr3,3dsmax,maxadapter.adp | Stop-Process -Force}}
}

if (!(($node -eq \"XXX158\") -or ($node -eq \"XXX159\") -or ($node -eq \"XXX163\") -or ($node -eq \"XXX164\")))
{

If ((([math]::round(((Get-WmiObject -computername $node -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2)) -le 1) -and ((Get-Service -ComputerName $node -Name \"BACKBURNER_SRV_200\" -ErrorAction \"SilentlyContinue\").status -eq \"Running\"))
{
InlineScript {invoke-command -computername $node {Stop-Service -Name \"BACKBURNER_SRV_200\"}}
}
elseif ((([math]::round(((Get-WmiObject -computername $node -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2)) -gt 4) -and ((Get-Service -ComputerName $node -Name \"BACKBURNER_SRV_200\" -ErrorAction \"SilentlyContinue\").status -eq \"Stopped\"))
{
InlineScript {invoke-command -computername $node {Start-Service -Name \"BACKBURNER_SRV_200\"}}
}

If ((Get-Service -ComputerName $node -Name \"BACKBURNER_SRV_200\" -ErrorAction \"SilentlyContinue\").status -eq \"Running\")
{
If (InlineScript {
(!( (invoke-command -computername $node {((gps serversvc).priorityclass)}) -eq \"Idle\"))
}
)
{
InlineScript {invoke-command -computername $node {(gps serversvc).priorityclass = \"Idle\"}}
}
}
}
}
}


Do {
check_Backburner ((Get-HpcNode -Scheduler XXX117).netbiosname)

Clear-Host
get-date | out-default
Write-Output \" \"

Get-HpcNode -Scheduler XXX117 | Sort-Object \"NetBiosName\" | Format-table -property `
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"NetBiosName\";Expression={$_.netbiosname}; alignment=\"center\"},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"freemem\";Expression={([math]::round(((Get-WmiObject -computername $_.netbiosname -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2))}; alignment=\"center\"},`
@{label=\"freedisk\";Expression={([math]::round(((get-wmiobject -computer $_.netbiosname win32_logicaldisk -Filter \"drivetype=3\").freespace/1GB),2))}; alignment=\"center\"},`
@{label=\"NodeState\";Expression={$_.NodeState}; alignment=\"center\"},`
@{label=\"Health\";Expression={$_.NodeHealth}; alignment=\"center\"},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"Orcaflex\"; Expression={(Get-Service -ComputerName $_.netbiosname -Name \"DOFClientService\").status};width=8},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"3DSMax service & priority\"; Expression={(Get-Service -ComputerName $_.netbiosname -Name \"BACKBURNER_SRV_200\").status;invoke-command -computername $_.netbiosname {((gps serversvc).priorityclass)} }},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"},`
@{label=\"Groups\";Expression={$_.Groups}; alignment=\"left\"},`
@{label=\"|\";Expression={\"|\"}; alignment=\"center\"} -AutoSize


job list /user:* /state:Running
Start-Sleep 300
Clear-host
} While ($true)
[/code:1]

Et les erreurs qui apparaissent :

oke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the
command again.
At check_Backburner:30 char:30
+
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : [localhost]

Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the
command again.
At check_Backburner:30 char:30
+
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : [localhost]

Microsoft.PowerShell.Utility\Write-Error : Couldn't connect to remote machine.
At check_Backburner:28 char:28
+
+ CategoryInfo : NotSpecified: (:) [Write-Error], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.WriteErrorCommand
+ PSComputerName : [localhost]

Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the
command again.
At check_Backburner:30 char:30
+
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : [localhost]

Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the
command again.
At check_Backburner:25 char:25
+
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : [localhost]

Si vous etes arrivé jusqu'ici je vous remercie d'avoir pris le temps de lire :p

Cdt,

Sebastien<br><br>Message édité par: sebasti1, à: 25/03/13 14:58

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

Plus d'informations
il y a 12 ans 11 mois #14441 par sebastien
Réponse de sebastien sur le sujet Re:Problèmes de Workflow
Je m'auto répond puisque j'ai compris mon erreur et cela pourra peut être servir a quelqu'un d'autre.
La commande
Les variables ne sont pas visible dans le block InlineScript.

Ressource utilisée : technet.microsoft.com/fr-fr/library/jj574197.aspx

exemple fonctionnel :

[code:1]
Workflow check_Backburner
{
param ([array]$nodes)

ForEach -Parallel ( $node in $nodes)
{
InlineScript {[math]::round(((Get-WmiObject -ComputerName $Using:node -Class Win32_OperatingSystem).FreePhysicalMemory / 1024 / 1024), 2) }
}
}
check_Backburner ((Get-HpcNode -Scheduler xxx).netbiosname)
[/code:1]

Cdt,

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

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