Question Plusieures actions sous une condition

Plus d'informations
il y a 11 ans 4 mois #18762 par Toper
Bonjour,
comme le titre l'indique, je n'arrive pas à regrouper plusieurs actions sous une condition.
Voici un exemple qui a autant de conditions que d'actions:
[code:1]if ($osarchitecture -match \"64 bits\" -and $osname -match \"Windows 7\")
{
(Write-Host \"W7 64bits\")
(Copy-Item \"D:\##Softwares\CobianBackup10\MainList.lst\" \"C:\Program Files(X86)\Cobian Backup 10\DB\")
(get-Content $MainList64Bits) |
ForEach-Object {
$_ = $_ -replace \"USERNAME\", \"$username\"
$_ = $_ -replace \"computername\", \"$Computername\"
} | set-content $MainList64Bits
}
if ($osarchitecture -match \"64 bits\" -and $osname -match \"Windows 7\"«»)
{
(New-Item -type file \"C:\Program Files(X86)\Cobian Backup 10\DB\{A5620BC8-AB2D-4450-9B01-20CCDD0B2B8B}.cbu\"«»)
}
if ($osarchitecture -match \"64 bits\" -and $osname -match \"Windows 7\"«»)
{
(Get-Content $cbEngine64Bits) |
ForEach-Object {
$_ = $_ -replace \"USERNAME\", \"$username\"
$_
} | Set-Content $cbEngine64Bits
}
[/code:1]

Ici trois actions, mais j'aimerai les regrouper sous une seule condition If.<br><br>Message édité par: gregmurf, à: 8/01/15 09:09

Powershell: la vie est belle :)

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

Plus d'informations
il y a 11 ans 4 mois #18763 par Philippe
salut gregmurf

Ici trois actions, mais j'aimerai les regrouper sous une seule condition If.

si tu comprend que tu a trois condition if identique, c'est tu sais comment elles sont constitué et donc de supprimé les deux if en trop

l'indentation t'aidera a mieux voir ton code et donc de mieux supprimé les lignes identiques et de regroupe les actions. exemple d'indentation :
[code:1]
if (condition) {
action
}

if (condition) {
action
action
}
else {
action | action | action | action | action
action
if (condition) {
action
}
action
}

if (condition) {
action
action | boucle {
action
}
action
}
[/code:1]<br><br>Message édité par: 6ratgus, à: 8/01/15 09:34

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

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