Table des matières

With GUI

  • 2 Arguments with the script
  • In the ‘Task ID’ field, add our Task ID
  • In the computer section, add the workstations to be added to the task

Powershell Script

[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

Don’t forget to change the name of your IVANTI EPM server in the script (line 36).

Console-mode script

2 arguments to the script:

  1. The TXT file (may be a future modification for CSV import).
  2. The Task ID number.

Note: Change the URL with the name of your LANDESK server.

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 => Allows you to see all available functions on your EPM core server

Catégories : EPM

0 commentaire

Laisser un commentaire

Emplacement de l’avatar

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.