Wie kann ich ein PowerShell-Skript mit dem X-Button beenden?

Ich habe eine MessageBox und möchte das Skript beenden, sobald X gedrückt wird.

Kann ich eine Variable hochzählen, wenn ein anderer Button gedrückt wird? Eine Variable, die verhindert, dass mein Skript beendet wird? Mit onClick oder so?

$version = "xy"
Add-Type -AssemblyName System.Windows.Forms

[System.Windows.Forms.Application]::EnableVisualStyles()

$START = New-Object system.Windows.Forms.Form
$START.ClientSize = '400,282'
$START.text = $version
$START.TopMost = $false
$Label1a = New-Object system.Windows.Forms.Label
$Label1a.text = "Inhaltt:"
$Label1a.AutoSize = $true
#$Label1a.width = 25
#$Label1a.height = 10
$Label1a.location = New-Object System.Drawing.Point(9, 24)
$Label1a.Font = 'Microsoft Sans Serif,10'
$Button1a = New-Object system.Windows.Forms.Button
$Button1a.text = "OK"
$Button1a.width = 381
$Button1a.height = 30
$Button1a.location = New-Object System.Drawing.Point(9, 243)
$Button1a.Font = 'Microsoft Sans Serif,10'
$Button1a.add_Click({$START.close()}) #MessageBox wird geschlossen
$TextBox1a = New-Object system.Windows.Forms.TextBox
#$TextBox1a.multiline = $false
$TextBox1a.text = "Inhalt"
$TextBox1a.width = 55
$TextBox1a.height = 20
$TextBox1a.location = New-Object System.Drawing.Point(9, 45)
$TextBox1a.Font = 'Microsoft Sans Serif,10'
$TextBox2a = New-Object system.Windows.Forms.TextBox
#$TextBox2.multiline = $false
$TextBox2a.text = "Inhalt"
$TextBox2a.width = 381
$TextBox2a.height = 20
$TextBox2a.location = New-Object System.Drawing.Point(9, 119)
$TextBox2a.Font = 'Microsoft Sans Serif,10,style=Italic'
$Label2a = New-Object system.Windows.Forms.Label
$Label2a.text = "Inhalt:" #$inputpath #Variable muss noch definiert werden
$Label2a.AutoSize = $true
#$Label2a.width = 25
#$Label2a.height = 10
$Label2a.location = New-Object System.Drawing.Point(9, 98)
$Label2a.Font = 'Microsoft Sans Serif,10'
$Label3a = New-Object system.Windows.Forms.Label
$Label3a.text = "Inhalt:" #$outputpath
$Label3a.AutoSize = $true
#$Label3a.width = 25
#$Label3a.height = 10
$Label3a.location = New-Object System.Drawing.Point(9, 172)
$Label3a.Font = 'Microsoft Sans Serif,10'
$TextBox3a = New-Object system.Windows.Forms.TextBox
#$TextBox3a.multiline = $false
$TextBox3a.text = "Inhalt"
$TextBox3a.width = 381
$TextBox3a.height = 20
$TextBox3a.location = New-Object System.Drawing.Point(9, 192)
$TextBox3a.Font = 'Microsoft Sans Serif,10,style=Italic'
$START.controls.AddRange(@($Label1a, $Button1a, $TextBox1a, $TextBox2a, $Label2a, $Label3a, $TextBox3a, $Label1ab))

[void]$START.ShowDialog()
Computer, Windows, programmieren, Code, Script, PowerShell, Powershell ISE
PowerShell: "Es wurde kein Positionsparameter gefunden, der das Argument "+" akzeptiert." Wie löse ich das?

Hi

Es geht um Reports... Programmiert wurde es mit PowerShell ISE

Hier der Fehler:

Rename-Item : Es wurde kein Positionsparameter gefunden, der das    Argument  "+" akzeptiert.
In Zeile:34 Zeichen:1
+ rename-item "c:\Reporting\Report_Telephone_" + $todaydate[0] +'-' + $todaydate[1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Rename-Item], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand

hier mein Code:

#today's date (year-month-day)
$todaydate = Get-Date -Format yyyy-MM-dd

#arrays  (today => systemtime)
$todaydate = $todaydate.Split('-')
$todaydate[0] #year
$todaydate[1] #month
$todaydate[2] #day

#arrays yesterday (systemtime - one day)
$yesterdaysdate = Get-Date((Get-Date).AddDays(-1)) -Format yyyy-MM-dd
$yesterdaysdate = $yesterdaysdate.Split('-')
$yesterdaysdate[0] #year
$yesterdaysdate[1] #month
$yesterdaysdate[2] #day

#arrays yesterday (systemtime - one day)
$lastmonth = Get-Date((Get-Date).AddMonths(-1)) -Format yyyy-MM-dd
$lastmonth = $lastmonth.Split('-')
$lastmonth[0] #year
$lastmonth[1] #month
$lastmonth[2] #day


#Example 1:  Filename "Report_Telephone_yyyy-mm" => in this case "Report_Telephone_2016-12"
#it renames the file -> minus one month, so the name must be "Report_Telephone_2016-11"
$filename='Report_Telephone_'+ $lastmonth[0]+'-'+ $lastmonth[1] + '.xlsx'
$filemonth = [int][regex]::Match($filename, '\w+_\d+_(\d+)').Groups[1].Value
$filemonth = "{0:D2}" -f ($filemonth - 1)

write-host $filename
rename-item "c:\Reporting\Report_Telephone_" + $todaydate[0] +'-' + $todaydate[1] + ".xlsx" -NewName $filename

$sourcepath='C:\Reporting\'+ $filename
write-host $sourcepath
$destinationpath='C:\Reporting\'+ $lastmonth[0]+'\'+ $lastmonth[1]
write-host $destinationpath
if(test-path $destinationpath)
{

} 
else 
  {
     mkdir $destinationpath
  }
move-item -path $sourcepath -destination $destinationpath

Hat einer ne Idee, wie ich das lösen könnte? Thx im vorraus :3

PC, Computer, Windows, IT, programmieren, Informatik, PS, Report, Script, PowerShell, Powershell ISE

Meistgelesene Beiträge zum Thema Powershell ISE