Greetings! This is my first post in the forums, and my first time on powershell.org. I am new to Powershell, however, I understand how powerful and useful it is in the Windows realm. I have the following scenario that I would like to request some assistance/guidance with since my Powershell skills are pretty much non-existent and I am trying to learn as I go.
Scenario: I am trying to write a powershell script that can be run at startup, as system or service, by use of GPO, or manually by an administrator. I would like to script to check for a Windows registry watermark first. If the watermark, exists, that means that the script has already ran and does not to be run again, so essentially the script would end without any action. If the watermark does not exist, I would like for it to create the watermark, then proceed to check the model of the computer. Based upon the what comes after CF-53 in the model name, it would pretty much use a case structure to install the appropriate drivers for the matching model. I will have exported the Windows DriverStore for different variants of the CF-53 and loaded them at C:\Drivers with the following folders within:
CF53mk1Drivers
CF53mk2Drivers
CF53mk3Drivers
CF53mk4Drivers
If the model of the computer began with CF-531, then the script would go through all of the drivers in the folder CF53mk1Drivers and install them recursively, forcing the install even if the publisher cannot be verified. I have drafted up the following code, but have not been able to test it because I have not finished building the driverstore on the different variants.
# Get computer model $a = (Get-WmiObject -Class Win32_ComputerSystem -Property * | Select-Object -Property Manufacturer, Model) Write-Host "Manufacturer is: $($a.Manufacturer)" -ForegroudColor Green Write-Host "Model is: $($a.Model)" -ForegroundColor Green # Check to see if registry watermark exists $b = (Test-Path "HKLM:\Test") If ($b = "False") { # Add registry watermark if it does not exist New-Item -Path "HKLM:\Test" -Force #Install Driver for Panasonic Toughbook CF 53 MK1 If $a.Model = "CF-531"{ Write-Host "Installing drivers for Panasonic Toughbook CF 53 MK1" -ForegroundColor Yellow Add-WindowsDriver -Driver "C:\Drivers\CF53mk1Drivers" -Recurse -ForceUnsigned } #Install Driver for Panasonic Toughbook CF 53 MK2 If $a.Model = "CF-532"{ Write-Host "Installing drivers for Panasonic Toughbook CF 53 MK2" -ForegroundColor Yellow Add-WindowsDriver -Driver "C:\Drivers\CF53mk2Drivers" -Recurse -ForceUnsigned } #Install Driver for Panasonic Toughbook CF 53 MK3 If $a.Model = "CF-533"{ Write-Host "Installing drivers for Panasonic Toughbook CF 53 MK3" -ForegroundColor Yellow Add-WindowsDriver -Driver "C:\Drivers\CF53mk3Drivers" -Recurse -ForceUnsigned } #Install Driver for Panasonic Toughbook CF 53 MK4 If $a.Model = "CF-534"{ Write-Host "Installing drivers for Panasonic Toughbook CF 53 MK4" -ForegroundColor Yellow Add-WindowsDriver -Driver "C:\Drivers\CF53mk4Drivers" -Recurse -ForceUnsigned } } Else{ Write-Host "Drivers for $($a.Model) not found" -ForegroundColor Red }
If anyone can let me know if I am on the right path, or suggest updates to make it more efficient and work, I would greatly appreciate it!
Respectfully,
John