Forum Discussion
smorgan263
Feb 18, 2022Copper Contributor
How to use output from 1 script in another script ??
I am trying to take the output from Script 1 and execute the actions in Script 2 against it.
Script 1 = Select Device from a drop down list
Script 2 = Execute option 1 or 2 against the selected Device
They both work indendently but I can't figure out how to intergrate the two.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Select a Computer'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,120)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,120)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Please select a computer:'
$form.Controls.Add($label)
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 80
[void] $listBox.Items.Add(‘ORTECLAB001’)
[void] $listBox.Items.Add('ORTECLAB002’)
[void] $listBox.Items.Add('ORTECLAB003’)
[void] $listBox.Items.Add('ORTECLAB004’)
[void] $listBox.Items.Add('ORTECLAB005')
[void] $listBox.Items.Add('ORTECLAB006')
[void] $listBox.Items.Add('ORTECLAB007')
[void] $listBox.Items.Add('ORTECLAB008')
[void] $listBox.Items.Add('ORTECLAB009')
[void] $listBox.Items.Add('ORTECLAB010')
[void] $listBox.Items.Add('ORTECLAB011')
[void] $listBox.Items.Add('ORTECLAB012')
[void] $listBox.Items.Add('ORTECLAB013')
[void] $listBox.Items.Add('ORTEC00348')
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = \\10.X.X.253\c$\Users\smorgan\Documents\Shutdown.ps1 $x
}
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$x=args[0]
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Shutdown | Restart"
$objForm.Size = New-Object System.Drawing.Size(300,300)
$objForm.StartPosition = "CenterScreen"
$objForm.FormBorderStyle = "FixedSingle"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(205,220)
$CancelButton.Size = New-Object System.Drawing.Size(75,25)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$SButton = New-Object System.Windows.Forms.Button
$SButton.Location = New-Object System.Drawing.Size(15,220)
$SButton.Size = New-Object System.Drawing.Size(75,25)
$SButton.Text = "Shutdown"
$SButton.Add_Click({Stop-Computer -Force})
$objForm.Controls.Add($SButton)
$RButton = New-Object System.Windows.Forms.Button
$RButton.Location = New-Object System.Drawing.Size(110,220)
$RButton.Size = New-Object System.Drawing.Size(75,25)
$RButton.Text = "Restart"
$RButton.Add_Click({Restart-Computer -Force})
$objForm.Controls.Add($RButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,120)
$objLabel.Text = "Please ensure you have selected the correct LAC/E Box before proceeding."
$objForm.Controls.Add($objLabel)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
- tumtum1973Copper ContributorMake these scripts into Functions in one file and you can call them as needed.
PowerShell Scripting - Chapter 9 - Functions
https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7.2
Your Getting Started Guide to Powershell Functions
https://adamtheautomator.com/powershell-functions/
Thanks,
tumtum