Untitled
unknown
plain_text
2 years ago
5.6 kB
10
Indexable
# Check if the flag file exists if (Test-Path -Path "C:\Temp\UserInfoSubmitted.flag") { # The user information has already been submitted, so we exit the script exit } # Show a form to collect user information Add-Type -AssemblyName System.Windows.Forms $form = New-Object System.Windows.Forms.Form $form.Width = 500 $form.Height = 500 $form.Text = 'User Information' # Add the logo image to the form $logoUrl = 'https://img.endole.co.uk/?t=&l=a80ce83b0f883bd6a120042cc96a5d7c' $logoImage = New-Object System.Windows.Forms.PictureBox $logoImage.Width = 150 $logoImage.Height = 40 $logoImage.ImageLocation = $logoUrl $logoImage.SizeMode = 'AutoSize' $form.Controls.Add($logoImage) $fullNameLabel = New-Object System.Windows.Forms.Label $fullNameLabel.Location = New-Object System.Drawing.Point(10,300) $fullNameLabel.Size = New-Object System.Drawing.Size(100,20) $fullNameLabel.Text = 'Full Name:' $form.Controls.Add($fullNameLabel) $fullNameTextBox = New-Object System.Windows.Forms.TextBox $fullNameTextBox.Location = New-Object System.Drawing.Point(120,300) $fullNameTextBox.Size = New-Object System.Drawing.Size(250,20) $form.Controls.Add($fullNameTextBox) $locationLabel = New-Object System.Windows.Forms.Label $locationLabel.Location = New-Object System.Drawing.Point(10,240) $locationLabel.Size = New-Object System.Drawing.Size(100,20) $locationLabel.Text = 'Location:' $form.Controls.Add($locationLabel) $locationTextBox = New-Object System.Windows.Forms.TextBox $locationTextBox.Location = New-Object System.Drawing.Point(120,240) $locationTextBox.Size = New-Object System.Drawing.Size(250,20) $form.Controls.Add($locationTextBox) $okButton = New-Object System.Windows.Forms.Button $okButton.Location = New-Object System.Drawing.Point(120,380) $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(200,380) $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) $form.Topmost = $true $result = $form.ShowDialog() # Check if the user clicked OK if ($result -eq [System.Windows.Forms.DialogResult]::OK) { # Get the user information entered in the form $fullName = $fullNameTextBox.Text $location = $locationTextBox.Text # Get device information $serialNumber = Get-CimInstance -ClassName Win32_Bios | Select-Object SerialNumber $model = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Model $hostName = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name # Get # location information $geoLocation = (New-Object Net.WebClient).DownloadString("http://ip-api.com/json") | ConvertFrom-Json $latitude = $geoLocation.lat $longitude = $geoLocation.lon # Create a URL for the location on Google Maps $mapUrl = "https://www.google.com/maps/place/$latitude,$longitude" # Format the device information $deviceInformation = "`r`nDevice Information:`r`n`r`nSerial Number: $($serialNumber.SerialNumber)`r`nModel: $($model.Model)`r`nHost Name: $($hostName.Name)`r`n" # Format the location information $locationInformation = "`r`nLocation Information:`r`n`r`nLatitude: $latitude`r`nLongitude: $longitude`r`nMap URL: $mapUrl`r`n" # Add line breaks and spacing to the email body for improved readability $emailBody = "Full Name:`t$fullName`r`n`r`nLocation:`t$location`r`n`r`n `n`r`n$deviceInformation`r`nLocation Information:`r`n$locationInformation" # Configure the email message $emailFrom = 'no-reply@mach.co.uk' $emailTo = 'johng@mach.co.uk' $emailSubject = 'User Information' $emailBody = "Full Name: $fullName`r`nLocation: $location$deviceInformation$locationInformation" # Configure the SMTP settings $smtpServer = 'outlook.office365.com' $smtpPort = 587 $smtpUser = 'no-reply@mach.co.uk' $smtpPassword = 'Waq48045' # Send the email $smtpClient = New-Object System.Net.Mail.SmtpClient($smtpServer, $smtpPort) $smtpClient.EnableSsl = $true $smtpClient.Credentials = New-Object System.Net.NetworkCredential($smtpUser, $smtpPassword) $smtpClient.Send($emailFrom, $emailTo, $emailSubject, $emailBody) # Create a flag file to indicate that the user information has been submitted New-Item -ItemType File -Path "C:\Temp\UserInfoSubmitted.flag" -Force # Set the API key and Baserow table ID $apiKey = "GW3XNz5vF8oAzVkTdL5EwSxkywZBuH2e" $tableId = "142957" # Build the API endpoint URL $url = "https://api.baserow.io/api/database/tables/$tableId/rows/" # Build the request body $requestBody = @{ fields = @{ Full_Name = $fullName Location = $location Serial_Number = $serialNumber.SerialNumber Model = $model.Model Host_Name = $hostName.Name Latitude = $latitude Longitude = $longitude Map_URL = $mapUrl } } | ConvertTo-Json -Depth 2 # Send the request to add the row to the table Invoke-RestMethod -Method Post -Uri $url -Headers @{Authorization = "Token $apiKey"} -Body $requestBody -ContentType "application/json" # Display a confirmation message [System.Windows.Forms.MessageBox]::Show('User information sent and saved successfully.', 'Information', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information) }
Editor is loading...