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="250"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style TargetType="Label">
<Setter Property="Margin" Value="10,0,10,0"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="Margin" Value="10,0,10,0"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="10,0,10,0"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Background" Value="#FF123456"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Window.Resources>
<Grid>
<Label Content="Task ID" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Name="TaskID" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="23" Width="Auto" Margin="10,30,10,0"/>
<Label Content="Computer" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,80,0,0"/>
<TextBox Name="PC" AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="216" Width="Auto" Margin="10,110,10,0"/>
<Button Content="Add to task" Name="Add" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Width="Auto" Margin="10,0,10,10"/>
</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 "leblogosd\david"
$ldWS = New-WebServiceProxy -uri https://monserveur.domain.lan/MBSDKService/MsgSDK.asmx -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)
}
}
}
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:
- The TXT file (may be a future modification 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 "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
0 Comments