With GUI

  • 2 script arguments
  • In “Task ID”, add your task ID
  • In “Computer”, add the computers 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. Possible causes: .NET Framework is missing, PowerShell must be launched with -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"
# Web service URL
$Add.add_Click({
    if ($TaskID.Text -ne "") {
        $Task = $TaskID.Text
        $mycreds = Get-Credential -Credential "domain\account"
        $ldWS = New-WebServiceProxy -uri http://YOURSERVERURL/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 "") {
                    $ldWS.AddDeviceToScheduledTask($Task, $tt)
                }
                $ldWS.StartTaskNow($Task, "BUSY")
            }
        }
        Write-Host "End"
    } else {
        Write-Host "Error: Task ID is required"
    }
})

# Display UI object
$Form.ShowDialog() | out-null

Remember to change the name of your IVANTI EPM server in the script (line 36).

Script in Console Mode

2 script arguments:

  • The TXT file (could be modified in the future for CSV import)
  • 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 "mydomain\myaccount"
$ldWS = New-WebServiceProxy -uri http://myserverurl.domain.lan/MBSDKService/MsgSDK.asmx?WSDL -Credential $mycreds

$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.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.