Question Déploiement fichier

Plus d'informations
il y a 15 ans 5 mois #3297 par michault
Déploiement fichier a été créé par michault
Ca y est! Voilà un script entièrement paramétré qui dispatch un fichier et crée une tâches planifiée qui utilise ce fichier. Je dois dire qu Laurent m'a beaucoup aidé et que j'ai fait beaucoup de progrès grâce à lui.

[code:1]#DispatchTasks.ps1
# Paramètres: $ouparm :L'Unité d'Organisation dont on veut récupérer les ordinateurs. exemple \"Cn=Computers\"
# $drive : Disque exemple \"C$\"
# $folder : Dossier exemple \"BATCH\"
# $cmd : *.cmd exemple \"Defrag+Shutdown.cmd\"
# $job : *.job exemple \"DEFRAG.job\"
# $log : Fichier trace
Param($ouparm,$drive,$folder, $cmd,$job,$log)

#Définition des constantes
$domain = \",DC=domaine,DC=fr\"
$OU= $ouparm + $domain

$Batch=1|select Drive,Path,Name,FullPath
$Batch.Drive,$Batch.Path,$Batch.Name=$drive,$folder,$cmd
$Batch.FullPath=\"$($Batch.Drive)\$($Batch.Path)\$($Batch.Name)\"


get-QADComputer -searchRoot $OU | Select-Object Name | where {$_.Name -like 'PC*'} |
ForEach-Object {

$path = \"\\\" + $_.Name + \"\\" + $Batch.drive
$pathcmd = \"\\\" + $_.Name + \"\\" + $Batch.FullPath
$pathtasks = \"\\\" + $_.Name + \"\\" + $Batch.drive + \"\Windows\Tasks\\" + $job
$nametasks = $job.split('.job')
$Date = Get-Date -Format G

$result = Test-Path -Path $pathcmd
if ($result -eq $true)
{
$Date + \" : \" + $_.Name + \" : $($Batch.FullPath) trouvé\" | Out-File $log -Append -NoClobber
$result = Test-Path -Path $pathtasks
if ($result -eq $true)
{
$Date + \" : \" + $_.Name + \" : $($job) trouvé\" | Out-File $log -Append -NoClobber
}
else
{
schtasks /create /tn \"$($nametasks[0])\" /tr \"$($Batch.FullPath)\" /s $_.Name /sc once /st 05:00:00 /ru \"NT AUTHORITY\SYSTEM\"
$Date + \" : \" + $_.Name + \" : Tasks OK\" | Out-File $log -Append -NoClobber
}
}
else
{
Copy-Item \"c:\PWRSHELL\BATCH\\" -Destination $path -Recurse -ErrorAction SilentlyContinue -ErrorVariable Copyerror
if ($?)
{
$Date + \" : \" + $_.Name + \" : Copy OK\" | Out-File $log -Append -NoClobber
$result = Test-Path -Path $pathtasks
if ($result -eq $true)
{
$Date + \" : \" + $_.Name + \" : $($job) trouvé\" | Out-File $log -Append -NoClobber
}
else
{
schtasks /create /tn \"$($nametasks[0])\" /tr \"$($Batch.FullPath)\" /s $_.Name /sc once /st 05:00:00 /ru \"NT AUTHORITY\SYSTEM\"
$Date + \" : \" + $_.Name + \" : Copy + Tasks OK\" | Out-File $log -Append -NoClobber
}
}
else
{
$Date + \" : \" + $_.Name + \" : \" + $Copyerror | Out-File $log -Append -NoClobber
}
}
}[/code:1]

Je vais mettre à disposition une autre script qui exécute cette tâche.<br><br>Message édité par: Arnaud, à: 9/12/08 22:53

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

Plus d'informations
il y a 15 ans 5 mois #3305 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Déploiement fichier
Salut,
tu devrais signaler qu'il y a un prérequis : get-QADComputer.

Ou le tester en début de script comme ceci par exemple :

$null=Get-Command \&quot;get-QADComputer\&quot; -ea SilentlyContinue -ev missingRequired;
if ($missingRequired.Count -gt 0)
{ throw \&quot;le cmdlet get-QADComputer est inexistant. Voir www.quest.com/powershell/\";}


Tutoriels PowerShell

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

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