Greetings.
Please, I tried executing a custom GUI Form script on a remote desktop. But when ever I tried doing that i got the error message below. What could be best way to approach this.
C:\Powershell\scripts> Invoke-Command -ComputerName NGMXL9293LFM -ScriptBlock {Get-UCForm.ps1}
The term 'Get-UCForm.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
+ CategoryInfo : ObjectNotFound: (Get-UCForm.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : NGMXL1793LMM
<#---------------------------------------------------- code line Below ---------------------------------------------------------------------#>
function Get-UCform {
# init powershell GUI
Add-Type -AssemblyName System.windows.forms
#Create a new form
$UCInformationform = New-Object System.Windows.Forms.Form #Creating an object of the form.
$UCInformationform.ClientSize = '500, 300' #The form size height and widht
$UCInformationform.Text = 'LazyAdmin - Powershell GUI Example' #Main text at the top of the Form
$UCInformationform.BackColor = '#ffffff' #Defining the background color
<#------------- Content of the form Goes Below ----------------------#>
$title = New-Object System.Windows.Forms.Label #Creating an object of my title
$title.Text = 'Technical User Support'
$title.AutoSize = $true
#Defining the Min and Max with of the title form
$title.Width = 25
$title.Height = 10
#Position of the Element
$title.location = New-object system.Drawing.Point(50,50)
#Define the font type and size
$title.font = 'Microsoft Sans Serif, 13'
#Other elements
$Description = New-Object System.Windows.Forms.Label
$Description.Text = "Add a New construction site Printer"
$Description.Width = 450
$Description.Height = 50
$Description.AutoSize = $false
$Description.Location = New-Object System.Drawing.Point(50,50)
$Description.Font = 'Microsoft sans serif, 10'
#Using a Dropdown List
$Printertype = New-Object System.Windows.Forms.ComboBox
$Printertype.text = ""
$Printertype.Width = 170
$Printertype.AutoSize = $true
#add the items in the dropdown list
@('Canon','Hp') | ForEach-Object {[void] $Printertype.items.Add($_)}
#Select the Default Value
$Printertype.selectedIndex = 0
$Printertype.Location = New-Object System.Drawing.Point(20,210)
$Printertype.Font = 'Microsoft Sans Serif, 10'
#add the Element to the form
$UCInformationform.Controls.AddRange(@($title, $Description,$Printertype))
#Display The form
[void]$UCInformationform.ShowDialog()
}
Get-UCform