Hey Again! Long time no seen, just had an amazing vacation. How are you guys?
Now with some new pieces of stuff that I´ve been working on.
In our company, we have a lot of different models, and sometimes they deploy them without me knowing. And therefore I didn’t put in any drivers.
Goal:
- A pop-up box prompt while deploying a machine in MDT (this could work in SCCM also, not tested), So the installation doesn’t continue
- A mail with the model name, computer name, and deployment share name, So i can put the correct model drivers into the MDT workbench.
Solution:
I made a PowerShell script that solves this. You need to fill the parameters to make it work in your environment.
Like this
.\ComputerNotCertfied.ps1 -SMTPServer relay.liverpool.com -SMTPPort 25 -From Home@liverpool.com -To Away@liverpool.com
Little explanation of the parameters
-SMTPServer (To send an email without putting any credentials, I’m I using a SMTP relay)
-SMTPPort (And I need to specify the ports as well for the relay)
-From (From which address I want to specify )
-To (To which address I want to specify)
#Synopsis # ComputerNotCertfied.ps1 #DESCRIPTION #Make a step in MDT, and a popup will promt the user, that the "Computer is not certified, #a mail have been sent to the system administrator" #Then the script is sending a email to the system-admins. #And after that, Shuts down the computer. #Created: 2018-08-13 ##Version: 1.0 #Author : Pontus Wendt #Twitter: @pontuswendt #Blog : https://pontuswendt.blog #Disclaimer: This script is provided "AS IS" with no warranties, confers no rights and #is not supported by the author #EXAMPLE #ComputerNotCertfied.ps1 -SMTPServer relay.liverpool.com -SMTPPort 25 -From liverpool@anfield.com -to # liverpool@anfield.com #Parameters Param( [parameter(mandatory = $True, HelpMessage = "Name of the SMTP server?")] [ValidateNotNullOrEmpty()] $SMTPServer, [parameter(mandatory = $True, HelpMessage = "Name of the SMTP relay port?")] [ValidateNotNullOrEmpty()] $SMTPPort, [parameter(mandatory = $True, HelpMessage = "Which adress are you sending from?")] [ValidateNotNullOrEmpty()] $From, [parameter(mandatory = $True, HelpMessage = "Which adress are you sending to?")] [ValidateNotNullOrEmpty()] $To ) #Popup-message $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Computer is not certified, a mail have been sent to the system administrator.", 0, "Error", 0x0 + 0x1000) #Gather computer information $log = get-content "C:\MININT\SMSOSD\OSDLOGS\BDD.log" foreach ($line in $log) { if ($line -like "*DeployRoot is now =*") { $Deploymentshare = "Deploymentshare " + "$($line.split("=")[1].split(']')[0])" } } $Model = wmic computersystem get model $Make = wmic computersystem get manufacturer #Send mail with gathered information $Subject = "New Model to certify" $Body = "$Model `n $Make `n $Computername `n $Deploymentshare" Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort #Shutting down computer Stop-Computer
Guide:
- Copy this script ( ComputerNotCertfied.zip zip it up first 😉 ) into the script folder in your Deployment share.
- Make a new step in your MDT task sequence, Choose PowershellScript
- Put this script into an MDT Step, and specify the parameters you want to use.
PowerShell script: ComputerNotCertified.ps1
Parameters: -SMTPServer relay.liverpool.com -SMTPPort 25 -From Home@liverpool.com -To Away@liverpool.com
- Go to Options tab and click on Add button.
- Add then “If statement“, then choose “none”
- Mark “if none of the conditions are true, then Add Query WMI
- Now we need to specify the models that are already certified.
(Put in following text (in this example I put in the Virtual machine, in your case it could be “HP 820 G3”:
SELECT * FROM Win32_ComputerSystem WHERE Model Like “Virtual Machine”
- Click Ok, then Apply, close the Task Sequence.
- Then “Update Deployment Share”
- Done
How does it looks like when we run a computer that is not certified?
When the computer run the “Check If the computer is certified” step.
This will pop-up
When you click “Ok“, the computer stops and shuts down.
Then you check your mail inbox.
Voila! Now you got an email that they tried to run a un-certified model.
Thanks for reading
/Pontus