Question [RESOLU] Erreur execution script

Plus d'informations
il y a 10 ans 10 mois #20344 par David
Bonjour,

Je vous présente mon premier script et mon premier message sur ce forum

J'ai une erreur quand je fais un clic droit sur mon script et que je choisis executer avec PowerShell :

Type [System.Windows.Forms.MessageBox] introuvable : assurez-vous que
l'assembly contenant ce type est chargé.


Dans la console ISE il fonctionne bien mais la non ....

Je recherche une solution depuis un moment mais je trouve rien

Une idée ??

mon code au complet :

[code:1]$destination = \"C:\Backup\"

$folder = \"Desktop\",
\"Downloads\",
\"Favorites\",
\"Documents\",
\"Music\",
\"Pictures\",
\"Videos\",
\"AppData\Local\Mozilla\",
\"AppData\Local\Google\",
\"AppData\Roaming\Mozilla\"

###############################################################################################################

$username = gc env:username
$userprofile = gc env:userprofile
$appData = gc env:localAPPDATA

###### Restore data section ######

if ([IO.Directory]::Exists($destination + \"\\" + $username + \"\\"«»))
{
$OUTPUT= [System.Windows.Forms.MessageBox]::«»Show(\"Le dossier backup pour $username existe, on Restaure ?\" , \"Restauration\" , 4)

if ($OUTPUT -eq \"YES\"«»)
{
write-host -ForegroundColor green \"Restauration des donnees de $username\"
foreach ($f in $folder)
{
$currentLocalFolder = $userprofile + \"\\" + $f
$currentRemoteFolder = $destination + \"\\" + $username + \"\\" + $f
$currentFolderSize = (Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force | Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB
$currentFolderSizeRounded = [System.Math]::Round($currentFolderSize)
write-host -ForegroundColor cyan \" $f... ($currentFolderSizeRounded MB«»)\"
Copy-Item -ErrorAction silentlyContinue -recurse $currentLocalFolder $currentRemoteFolder

if ($f -eq \"AppData\Local\Mozilla\"«») { rename-item $currentLocalFolder \"$currentLocalFolder.old\" }
if ($f -eq \"AppData\Roaming\Mozilla\"«») { rename-item $currentLocalFolder \"$currentLocalFolder.old\" }
if ($f -eq \"AppData\Local\Google\"«») { rename-item $currentLocalFolder \"$currentLocalFolder.old\" }

}
rename-item \"$destination\$username\" \"$destination\$username.restore\"
[System.Windows.Forms.MessageBox]::«»Show(\"Restauration complete!\" , \"David\"«»)
}

else
{
write-host -ForegroundColor yellow \"Annulation\"
exit
}

}



###### Backup Data section ########

else
{
$OUTPUT= [System.Windows.Forms.MessageBox]::«»Show(\"Pret pour le backup de $username ?\" , \"Backup\" , 4)

if ($OUTPUT -eq \"YES\"«»)
{

Get-Process | Where { $_.Name -Eq \"OUTLOOK\" } | Kill

write-host -ForegroundColor green \"Backup des donnees de $username\"

foreach ($f in $folder)
{
$currentLocalFolder = $userprofile + \"\\" + $f
$currentRemoteFolder = $destination + \"\\" + $username + \"\\" + $f
$currentFolderSize = (Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force | Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB
$currentFolderSizeRounded = [System.Math]::Round($currentFolderSize)
write-host -ForegroundColor cyan \" $f... ($currentFolderSizeRounded MB«»)\"
Copy-Item -ErrorAction silentlyContinue -recurse $currentLocalFolder $currentRemoteFolder
}



$oldStylePST = [IO.Directory]::GetFiles($appData + \"\Microsoft\Outlook\", \"*.pst\"«»)
foreach($pst in $oldStylePST)
{
if ((test-path -path ($destination + \"\\" + $username + \"\Documents\Outlook Files\oldstyle\"«»)) -eq 0){new-item -type directory -path ($destination + \"\\" + $username + \"\Documents\Outlook Files\oldstyle\"«») | out-null}
write-host -ForegroundColor yellow \" $pst...\"
Copy-Item $pst ($destination + \"\\" + $username + \"\Documents\Outlook Files\oldstyle\"«»)
}

[System.Windows.Forms.MessageBox]::«»Show(\"Backup complet!\" , \"David\"«»)
}

else
{
write-host -ForegroundColor yellow \"Annulation\"
exit
}

}[/code:1]

Je l'ai trouvé sur le net et l'ai largement modifié pour mon utilisation

Merci d'avance<br><br>Message édité par: goro, à: 30/06/15 13:25

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

Plus d'informations
il y a 10 ans 10 mois #20347 par David
Réponse de David sur le sujet Re:Erreur execution script
On m'a donné la solution sur un autre forum :

il faut charger l'assembly dépendant :

[code:1]Add-Type -AssemblyName System.Windows.Forms[/code:1]


Si ca peut aider quelqu'un !

Merci en tout cas

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

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