tri_94 Posted July 3, 2020 Posted July 3, 2020 Hi I'm working on a basic GUI that has the ability to get ip, mac and last reboot time of a pc and also gives the ability to send the information as a email. The code below works for everything except the last reboot doesn't seem to work, not sure why as if i run it basically the same line direct it will. Other slight issue is the way in which is displays the information can any help make it more user friendly. Many Thanks Add-Type -AssemblyName System.Windows.Forms [system.Windows.Forms.Application]::EnableVisualStyles() $FormName = New-Object system.Windows.Forms.Form $FormName.ClientSize = '400,400' $FormName.text = "Form" $FormName.TopMost = $false $Label1 = New-Object system.Windows.Forms.Label $Label1.text = "Please Enter Computer Name" $Label1.AutoSize = $true $Label1.width = 25 $Label1.height = 10 $Label1.location = New-Object System.Drawing.Point(10,20) $Label1.Font = 'Microsoft Sans Serif,10' $TextBox1 = New-Object system.Windows.Forms.TextBox $TextBox1.multiline = $false $TextBox1.width = 374 $TextBox1.height = 20 $TextBox1.location = New-Object System.Drawing.Point(10,40) $TextBox1.Font = 'Microsoft Sans Serif,10' $Button1 = New-Object system.Windows.Forms.Button $Button1.text = "Click to Find IP \ Mac Address of Computer" $Button1.width = 374 $Button1.height = 30 $Button1.location = New-Object System.Drawing.Point(10,65) $Button1.Font = 'Microsoft Sans Serif,10' $Label2 = New-Object system.Windows.Forms.Label $Label2.text = "Email Address" $Label2.AutoSize = $true $Label2.width = 25 $Label2.height = 10 $Label2.location = New-Object System.Drawing.Point(11,320) $Label2.Font = 'Microsoft Sans Serif,10' $Button2 = New-Object system.Windows.Forms.Button $Button2.text = "Send As Email" $Button2.width = 150 $Button2.height = 25 $Button2.location = New-Object System.Drawing.Point(235,339) $Button2.Font = 'Microsoft Sans Serif,10' $TextBox2 = New-Object system.Windows.Forms.TextBox $TextBox2.multiline = $false $TextBox2.width = 220 $TextBox2.height = 20 $TextBox2.location = New-Object System.Drawing.Point(10,340) $TextBox2.Font = 'Microsoft Sans Serif,10' $OutputBox1 = New-Object system.Windows.Forms.TextBox $OutputBox1.width = 374 $OutputBox1.height = 200 $OutputBox1.multiline = $true $OutputBox1.location = New-Object System.Drawing.Point(10,100) $FormName.controls.AddRange(@($Label1,$TextBox1,$Button1,$Label2,$Button2,$Outputbox1,$Textbox2)) #$Global:data = "" $smtpServer = "" $Button1.Add_Click({Get-MAC }) $Button2.Add_Click({Send }) function Get-MAC { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "Computer Name"($Computer) $obj | Add-Member NoteProperty "IP Address" ($hostIp) $obj | Add-Member NoteProperty "Mac Address"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "Last Reboot"(Get-WmiObject win32_operatingsystem | select $Computer, @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}) $Outputbox1.Text = $obj } function Send { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "Computer Name"($Computer) $obj | Add-Member NoteProperty "IP Address" ($hostIp) $obj | Add-Member NoteProperty "Mac Address"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "Last Reboot"(get-eventlog system | where-object {$_.eventid -eq 6005} | select Timegenerated, EntryType, Source, Message -first 10) $obj | Add-Member NoteProperty "Last Reboot"(Get-WmiObject win32_operatingsystem | select $Computer, @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}) $Outputbox1.Text = $obj Write-Output $obj $EmailAddress = $Textbox2.Text Send-Mailmessage - smtpServer $smtpServer -from [email protected] -to $EmailAddress -subject "IP / MAC Details for $Computer" -body """$obj""" -bodyasHTML -priority High Write-Host "Button Clicked" } [void]$FormName.ShowDialog() 1
MartinByard Posted July 3, 2020 Posted July 3, 2020 Hi Tri_94, this seems to do the job - i haven't tested the email side of it as that is a bit awkward in my environment, but the form pulls back all the data - and displays it better. All that need changing was specifiying the computername on the Get-wmi for the reboot, and amending the select arguments after it, to take out the computername (i think). Add-Type -AssemblyName System.Windows.Forms [system.Windows.Forms.Application]::EnableVisualStyles() $FormName = New-Object system.Windows.Forms.Form $FormName.ClientSize = '400,400' $FormName.text = "Form" $FormName.TopMost = $false $Label1 = New-Object system.Windows.Forms.Label $Label1.text = "Please Enter Computer Name" $Label1.AutoSize = $true $Label1.width = 25 $Label1.height = 10 $Label1.location = New-Object System.Drawing.Point(10,20) $Label1.Font = 'Microsoft Sans Serif,10' $TextBox1 = New-Object system.Windows.Forms.TextBox $TextBox1.multiline = $false $TextBox1.width = 374 $TextBox1.height = 20 $TextBox1.location = New-Object System.Drawing.Point(10,40) $TextBox1.Font = 'Microsoft Sans Serif,10' $Button1 = New-Object system.Windows.Forms.Button $Button1.text = "Click to Find IP \ Mac Address of Computer" $Button1.width = 374 $Button1.height = 30 $Button1.location = New-Object System.Drawing.Point(10,65) $Button1.Font = 'Microsoft Sans Serif,10' $Label2 = New-Object system.Windows.Forms.Label $Label2.text = "Email Address" $Label2.AutoSize = $true $Label2.width = 25 $Label2.height = 10 $Label2.location = New-Object System.Drawing.Point(11,320) $Label2.Font = 'Microsoft Sans Serif,10' $Button2 = New-Object system.Windows.Forms.Button $Button2.text = "Send As Email" $Button2.width = 150 $Button2.height = 25 $Button2.location = New-Object System.Drawing.Point(235,339) $Button2.Font = 'Microsoft Sans Serif,10' $TextBox2 = New-Object system.Windows.Forms.TextBox $TextBox2.multiline = $false $TextBox2.width = 220 $TextBox2.height = 20 $TextBox2.location = New-Object System.Drawing.Point(10,340) $TextBox2.Font = 'Microsoft Sans Serif,10' $OutputBox1 = New-Object system.Windows.Forms.TextBox $OutputBox1.width = 374 $OutputBox1.height = 200 $OutputBox1.multiline = $true $OutputBox1.location = New-Object System.Drawing.Point(10,100) $FormName.controls.AddRange(@($Label1,$TextBox1,$Button1,$Label2,$Button2,$Outputbox1,$Textbox2)) #$Global:data = "" $smtpServer = "" $Button1.Add_Click({Get-MAC }) $Button2.Add_Click({Send }) function Get-MAC { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "ComputerName"($Computer) $obj | Add-Member NoteProperty "IPAddress" ($hostIp) $obj | Add-Member NoteProperty "MacAddress"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "LastReboot"((Get-WmiObject win32_operatingsystem -ComputerName $Computer | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}).LastBootUpTime) #$Outputbox1.Text = $obj $OutputBox1.Text = "Computer Name = " + $obj.ComputerName + " IP Address = " + $obj.IPAddress + " MAC Address = " + $obj.MacAddress + " Last Reboot = " + $obj.LastReboot } function Send { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "Computer Name"($Computer) $obj | Add-Member NoteProperty "IP Address" ($hostIp) $obj | Add-Member NoteProperty "Mac Address"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "Last Reboot"(get-eventlog system | where-object {$_.eventid -eq 6005} | select Timegenerated, EntryType, Source, Message -first 10) $obj | Add-Member NoteProperty "Last Reboot"(Get-WmiObject win32_operatingsystem -ComputerName $Computer | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}) #$Outputbox1.Text = $obj $OutputBox1.Text = "Computer Name = " + $obj.ComputerName + " IP Address = " + $obj.IPAddress + " MAC Address = " + $obj.MacAddress + " Last Reboot = " + $obj.LastReboot $EmailBody = "Computer Name = " + $obj.ComputerName + " IP Address = " + $obj.IPAddress + " MAC Address = " + $obj.MacAddress + " Last Reboot = " + $obj.LastReboot #Write-Output $obj $EmailAddress = $Textbox2.Text Send-Mailmessage -smtpServer $smtpServer -from [email protected] -to $EmailAddress -subject "IP / MAC Details for $Computer" -body $EmailBody -bodyasHTML -priority High Write-Host "Button Clicked" } [void]$FormName.ShowDialog()
tri_94 Posted July 3, 2020 Author Posted July 3, 2020 (edited) Thanks for it does show the details some much better now. I've tested the email side and slight change but it working now. When it emails is displays like Computer Name = mypc IP Address =000.000.000.000 MAC Address = AA:AA:AA:AA:AA:AA Last Reboot1 = 06/26/2020 11:17:36 Windows Version = Microsoft Windows 10 Enterprise 2016 LTSB Windows Build = 14393 Is there any way to include line spaces i've tried `n but maybe i did it wrong. Thanks again for your help. Edited July 3, 2020 by tri_94
MartinByard Posted July 3, 2020 Posted July 3, 2020 Try this one ... I'd left some spaces in the variable names for the email bit. The only query I've got is about the bit where you query the event log to get events with the ID 6005, and what thats actually meant to do (I've commented it out in this version). Add-Type -AssemblyName System.Windows.Forms [system.Windows.Forms.Application]::EnableVisualStyles() $FormName = New-Object system.Windows.Forms.Form $FormName.ClientSize = '400,400' $FormName.text = "Form" $FormName.TopMost = $false $Label1 = New-Object system.Windows.Forms.Label $Label1.text = "Please Enter Computer Name" $Label1.AutoSize = $true $Label1.width = 25 $Label1.height = 10 $Label1.location = New-Object System.Drawing.Point(10,20) $Label1.Font = 'Microsoft Sans Serif,10' $TextBox1 = New-Object system.Windows.Forms.TextBox $TextBox1.multiline = $false $TextBox1.width = 374 $TextBox1.height = 20 $TextBox1.location = New-Object System.Drawing.Point(10,40) $TextBox1.Font = 'Microsoft Sans Serif,10' $Button1 = New-Object system.Windows.Forms.Button $Button1.text = "Click to Find IP \ Mac Address of Computer" $Button1.width = 374 $Button1.height = 30 $Button1.location = New-Object System.Drawing.Point(10,65) $Button1.Font = 'Microsoft Sans Serif,10' $Label2 = New-Object system.Windows.Forms.Label $Label2.text = "Email Address" $Label2.AutoSize = $true $Label2.width = 25 $Label2.height = 10 $Label2.location = New-Object System.Drawing.Point(11,320) $Label2.Font = 'Microsoft Sans Serif,10' $Button2 = New-Object system.Windows.Forms.Button $Button2.text = "Send As Email" $Button2.width = 150 $Button2.height = 25 $Button2.location = New-Object System.Drawing.Point(235,339) $Button2.Font = 'Microsoft Sans Serif,10' $TextBox2 = New-Object system.Windows.Forms.TextBox $TextBox2.multiline = $false $TextBox2.width = 220 $TextBox2.height = 20 $TextBox2.location = New-Object System.Drawing.Point(10,340) $TextBox2.Font = 'Microsoft Sans Serif,10' $OutputBox1 = New-Object system.Windows.Forms.TextBox $OutputBox1.width = 374 $OutputBox1.height = 200 $OutputBox1.multiline = $true $OutputBox1.location = New-Object System.Drawing.Point(10,100) $FormName.controls.AddRange(@($Label1,$TextBox1,$Button1,$Label2,$Button2,$Outputbox1,$Textbox2)) #$Global:data = "" $smtpServer = "" $Button1.Add_Click({Get-MAC }) $Button2.Add_Click({Send }) function Get-MAC { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "ComputerName"($Computer) $obj | Add-Member NoteProperty "IPAddress" ($hostIp) $obj | Add-Member NoteProperty "MacAddress"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "LastReboot"((Get-WmiObject win32_operatingsystem -ComputerName $Computer | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}).LastBootUpTime) #$Outputbox1.Text = $obj $OutputBox1.Text = "Computer Name = " + $obj.ComputerName + " IP Address = " + $obj.IPAddress + " MAC Address = " + $obj.MacAddress + " Last Reboot = " + $obj.LastReboot } function Send { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "ComputerName"($Computer) $obj | Add-Member NoteProperty "IPAddress" ($hostIp) $obj | Add-Member NoteProperty "MacAddress"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress #$obj | Add-Member NoteProperty "LastBoots"(get-eventlog system -ComputerName $Computer | where-object {$_.eventid -eq 6005} | select Timegenerated, EntryType, Source, Message -first 10) $obj | Add-Member NoteProperty "LastReboot"((Get-WmiObject win32_operatingsystem -ComputerName $Computer | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}).LastBootUpTime) #$Outputbox1.Text = $obj $OutputBox1.Text = "Computer Name = " + $obj.ComputerName + " IP Address = " + $obj.IPAddress + " MAC Address = " + $obj.MacAddress + " Last Reboot = " + $obj.LastReboot $EmailBody = "Computer Name = " + $obj.ComputerName + " IP Address = " + $obj.IPAddress + " MAC Address = " + $obj.MacAddress + " Last Reboot = " + $obj.LastReboot Write-Host $obj Write-Host $EmailBody $EmailAddress = $Textbox2.Text #Send-Mailmessage -smtpServer $smtpServer -from [email protected] -to $EmailAddress -subject "IP / MAC Details for $Computer" -body $EmailBody -bodyasHTML -priority High Write-Host "Button Clicked" } [void]$FormName.ShowDialog()
tri_94 Posted July 3, 2020 Author Posted July 3, 2020 (edited) Sorry think you were replying at the same time. This bit you've take out was left over from before, is was a different way of finding last reboot time by querying event log. I had already removed it from Get-Mac but not Send. Edited July 3, 2020 by tri_94
tri_94 Posted July 3, 2020 Author Posted July 3, 2020 I've now got the spacing working on the emails. I removed -bodyasHTML. There is still a couple of issues, for Model, Serial and OU I get @{}, So like model returns @{Model=OptiPlex 3060} is there an easy way to remove the @{} ? Also for Windows Updates doesn't seem to work for, if I run the command direct it does. Many thanks Add-Type -AssemblyName System.Windows.Forms [system.Windows.Forms.Application]::EnableVisualStyles() $FormName = New-Object system.Windows.Forms.Form $FormName.ClientSize = '400,400' $FormName.text = "Form" $FormName.TopMost = $false $Label1 = New-Object system.Windows.Forms.Label $Label1.text = "Please Enter Computer Name" $Label1.AutoSize = $true $Label1.width = 25 $Label1.height = 10 $Label1.location = New-Object System.Drawing.Point(10,20) $Label1.Font = 'Microsoft Sans Serif,10' $TextBox1 = New-Object system.Windows.Forms.TextBox $TextBox1.multiline = $false $TextBox1.width = 374 $TextBox1.height = 20 $TextBox1.location = New-Object System.Drawing.Point(10,40) $TextBox1.Font = 'Microsoft Sans Serif,10' $Button1 = New-Object system.Windows.Forms.Button $Button1.text = "Click to Find IP \ Mac Address of Computer" $Button1.width = 374 $Button1.height = 30 $Button1.location = New-Object System.Drawing.Point(10,65) $Button1.Font = 'Microsoft Sans Serif,10' $Label2 = New-Object system.Windows.Forms.Label $Label2.text = "Email Address" $Label2.AutoSize = $true $Label2.width = 25 $Label2.height = 10 $Label2.location = New-Object System.Drawing.Point(11,320) $Label2.Font = 'Microsoft Sans Serif,10' $Button2 = New-Object system.Windows.Forms.Button $Button2.text = "Send As Email" $Button2.width = 150 $Button2.height = 25 $Button2.location = New-Object System.Drawing.Point(235,339) $Button2.Font = 'Microsoft Sans Serif,10' $TextBox2 = New-Object system.Windows.Forms.TextBox $TextBox2.multiline = $false $TextBox2.width = 220 $TextBox2.height = 20 $TextBox2.location = New-Object System.Drawing.Point(10,340) $TextBox2.Font = 'Microsoft Sans Serif,10' $OutputBox1 = New-Object system.Windows.Forms.TextBox $OutputBox1.width = 374 $OutputBox1.height = 200 $OutputBox1.multiline = $true $OutputBox1.location = New-Object System.Drawing.Point(10,100) $FormName.controls.AddRange(@($Label1,$TextBox1,$Button1,$Label2,$Button2,$Outputbox1,$Textbox2)) #$Global:data = "" $smtpServer = "" $Button1.Add_Click({Get-MAC }) $Button2.Add_Click({Send }) function Get-MAC { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "ComputerName"($Computer) $obj | Add-Member NoteProperty "IPAddress" ($hostIp) $obj | Add-Member NoteProperty "MacAddress"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "LastReboot"((Get-WmiObject win32_operatingsystem -ComputerName $Computer | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}).LastBootUpTime) $obj | Add-Member NoteProperty "WindowsVersion"(Get-WmiObject -class Win32_OperatingSystem -ComputerName $Computer ).Caption $obj | Add-Member NoteProperty "WindowsBuild"(get-wmiobject -class win32_OperatingSystem -ComputerName $Computer ).BuildNumber $obj | Add-Member NoteProperty "OU" (Get-ADComputer -Identity $Computer | Select-Object DistinguishedName) $obj | Add-Member NoteProperty "Model" (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | Select-Object -Property Model) $obj | Add-Member NoteProperty "SerialNumber" (Get-WmiObject Win32_BIOS -ComputerName $Computer| Select-Object -Property SerialNumber) $obj | Add-Member NoteProperty "WindowsUpdates"(get-hotfix -ComputerName $Computer | Select-Object HotfixID) $OutputBox1.Text = "Computer Name = " + $obj.ComputerName + " Computer Name:" + $obj.ComputerName + " IP Address: " + $obj.IPAddress + " MAC Address: " + $obj.MacAddress + " Computer Model: " + $obj.Model + " Computer Serial: " + $obj.SerialNumber + " Last Rebooted: " + $obj.LastReboot + " Windows Version: " + $obj.WindowsVersion + " Windows Build: " + $obj.WindowsBuild + " Computer OU: " + $obj.OU +" Windows Updates = " + $obj.WindowsUpdates } function Send { $Computer = $Textbox1.Text if($Computer -eq $null) { $Computer = $env:COMPUTERNAME } $hostIp = [system.Net.Dns]::GetHostByName($Computer).AddressList[0].IpAddressToString if($Credential) { $Credential = Get-Credential $Credential $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -Credential $Credential -ComputerName $Computer } else { $wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer } $obj = New-Object PSObject $obj | Add-Member NoteProperty "ComputerName"($Computer) $obj | Add-Member NoteProperty "IPAddress" ($hostIp) $obj | Add-Member NoteProperty "MacAddress"($wmi | where { $_.IpAddress -eq $hostIp }).MACAddress $obj | Add-Member NoteProperty "LastReboot"((Get-WmiObject win32_operatingsystem -ComputerName $Computer | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}).LastBootUpTime) $obj | Add-Member NoteProperty "WindowsVersion"(Get-WmiObject -class Win32_OperatingSystem -ComputerName $Computer ).Caption $obj | Add-Member NoteProperty "WindowsBuild"(get-wmiobject -Class win32_OperatingSystem -ComputerName $Computer ).BuildNumber $obj | Add-Member NoteProperty "OU" (Get-ADComputer -Identity $Computer | Select-Object DistinguishedName) $obj | Add-Member NoteProperty "Model" (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | Select-Object -Property Model) $obj | Add-Member NoteProperty "SerialNumber" (Get-WmiObject Win32_BIOS -ComputerName $Computer| Select-Object -Property SerialNumber) $obj | Add-Member NoteProperty "WindowsUpdates"(get-hotfix -ComputerName $Computer | Select-Object HotfixID) $EmailBody =" Computer Name: " + $obj.ComputerName + "`n IP Address: " + $obj.IPAddress + "`n MAC Address: " + $obj.MacAddress + "`n Computer Model: " + $obj.Model + "`n Computer Serial: " + $obj.SerialNumber + " `n Last Rebooted: " + $obj.LastReboot + "`n Windows Version: " + $obj.WindowsVersion + "`n Windows Build: " + $obj.WindowsBuild + "`n Computer OU: " + $obj.OU + "`n`n Windows Updates = " + $obj.WindowsUpdates $EmailAddress = $Textbox2.Text Send-Mailmessage -smtpServer $smtpServer -from [email protected] -to $EmailAddress -subject "IP / MAC Details for $Computer" -body $EmailBody -priority High Write-Host "Button Clicked" } [void]$FormName.ShowDialog()
MartinByard Posted July 3, 2020 Posted July 3, 2020 (edited) For the OU query, try using $obj | Add-Member NoteProperty "OU" (Get-ADComputer -Identity $Computer | Select-Object DistinguishedName).DistinguishedName For the Model query, try using $obj | Add-Member NoteProperty "Model" (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | Select-Object -Property Model).Model For the Serial number, try using $obj | Add-Member NoteProperty "SerialNumber" (Get-WmiObject Win32_BIOS -ComputerName $Computer| Select-Object -Property SerialNumber).SerialNumber For the hotfix, try using $obj | Add-Member NoteProperty "WindowsUpdates"(get-hotfix -ComputerName $Computer | Select-Object HotfixID).HotfixID that should fetch just the actual values you want and put it in the $obj array. Edited July 3, 2020 by MartinByard 1
tri_94 Posted July 3, 2020 Author Posted July 3, 2020 (edited) Them 4 work perfect thanks for that. Edited July 3, 2020 by tri_94
HPlum78 Posted July 3, 2020 Posted July 3, 2020 (edited) @tri_94 seems like you are almost building SCOM here, or getting close to windows admin centre! I love me a script but sometimes I love a single window. So I will point you at https://github.com/ironmansoftware/universal-dashboard This maybe a better place to start:- https://docs.ironmansoftware.com/ (there is a community version FOC) Just food for thought, clearly if I get time I will input into your scripts Edited July 3, 2020 by HPlum78
tri_94 Posted July 8, 2020 Author Posted July 8, 2020 Thanks for that when i have some time i'll have a look into it. @tri_94 seems like you are almost building SCOM here, or getting close to windows admin centre! I love me a script but sometimes I love a single window. So I will point you at https://github.com/ironmansoftware/universal-dashboard This maybe a better place to start:- https://docs.ironmansoftware.com/ (there is a community version FOC) Just food for thought, clearly if I get time I will input into your scripts
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now