Avec une interface
- 2 arguments au script
- Dans « Task ID » Ajouter l’ID de votre tache
- Dans computer, ajouter les postes à ajouter à la tâche
Le script Powershell
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = @'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Add To Task" Height="450" Width="197.848">
<Grid>
<Button Content="Add to task" Name="Add" HorizontalAlignment="Left" Margin="21,362,0,0" VerticalAlignment="Top" Width="142"/>
<Label Content="task ID" HorizontalAlignment="Left" Margin="21,16,0,0" VerticalAlignment="Top" Width="142"/>
<Label Content="Computer" HorizontalAlignment="Left" Margin="21,106,0,0" VerticalAlignment="Top" Width="142"/>
<TextBox HorizontalAlignment="Left" Name="TaskID" Height="23" Margin="21,42,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="142"/>
<TextBox HorizontalAlignment="Left" Name="PC" AcceptsReturn="True" Height="216" Margin="21,132,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="142"/>
</Grid>
</Window>
'@
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit}
#===========================================================================
# Store Form Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$ofs="`r`n"
# http://localhost/MBSDKService/MsgSDK.asmx?WSDL/GetMachineData
$Add.add_Click({
If ($TaskID.Text -ne "") {
$Task = $TaskID.Text
$mycreds = Get-Credential -Credential "domaine\compte"
$ldWS = New-WebServiceProxy -uri http://VOTRESERVEURLANDESK/MBSDKService/MsgSDK.asmx?WSDL -Credential $mycreds
Foreach ($ComputerName in $PC.Text) {
$ComputerName = $ComputerName.Trim()
$Temp = $ComputerName.split($ofs)
Foreach ($tt in $Temp) {
$tt = $tt.Trim()
If ($tt -ne "") {
#write-host ">>>$ldWS.AddDeviceToScheduledTask($Task, $tt)<<<"
$ldWS.AddDeviceToScheduledTask($Task, $tt)
}
$ldWS.StartTaskNow($Task, "BUSY")
}
}
write-host "End"
} else {
write-host "Error task ID"
}
})
# Display UI object
$Form.ShowDialog() | out-null
N’oublier pas de changer le nom de votre serveur IVANTI EPM dans le script (ligne 36)
Script en mode console
2 arguments au script
- Le fichier TXT (peut être une modification future pour un import en CSV)
- Le numéro de la task ID
Note : Changer l’url avec le nom de votre serveur LANDESK
Param(
[parameter(Mandatory=$true)][String]$FichierCSV,
[parameter(Mandatory=$true)][String]$TaskID
)
$mycreds = Get-Credential -Credential "mondomaine\dwuibail_adm"
$ldWS = New-WebServiceProxy -uri http://coreserveurlandesk.domaine.lan/MBSDKService/MsgSDK.asmx?WSDL -Credential $mycreds
# $ldWS.ListMachines("").Devices | Format-Table *
$CSV = Get-Content $FichierCSV
foreach ($line in $CSV) {
$ldWS.AddDeviceToScheduledTask($TaskID, $line)
}
http://localhost/MBSDKService/MsgSDK.asmx?WSDL/GetMachineData => Permet de voire toutes les fonctions disponibles sur votre core server EPM
0 commentaire