1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[System.String]$user = (Get-WMIObject -ClassName Win32_ComputerSystem).Username [System.String]$ip = (Get-NetIPConfiguration | Where-Object { $_.IPv4DefaultGateway -ne $null }).IPv4Address.IPAddress [System.Text.Encoding]$encode = [System.Text.Encoding]::UTF8 # Add-Type -AssemblyName System.Windows.Forms # [System.Windows.Forms.MessageBox]::Show($user) # [System.Windows.Forms.MessageBox]::Show($ip) [System.String]$SMTPServer = "xxx" [System.String]$SMTPPort = "587" [System.String]$Username = "xxx@xxx" [System.Security.SecureString]$Password = ConvertTo-SecureString "xxx" -AsPlainText -Force [System.String]$From = "xxx@xxx" [System.String]$To = "xxx@xxx" [System.String]$Subject = "ユーザー名, IPアドレス" [System.String]$Body = $user + "`r`n" + $ip [System.Collections.Hashtable]$SMTPMessage = @{ To = $To From = $From Subject = $Subject Body = $Body SmtpServer = $SMTPServer Port = $SMTPPort UseSSL = $true Credential = New-Object System.Management.Automation.PSCredential ($Username, $Password) Encoding = $encode } Send-MailMessage @SMTPMessage |