Help with PS Project

Hello All! I need help with my powershell project.

Goal Overview:

  1. Get all of the systems Hardware IDs and Device IDs

  2. Look through all the Hardware IDs and Device IDs and when it makes a match, it’ll go and execute a specific driver.

2a) If the Hardware ID or Device ID gets a match, check to see if the drivers / software is already installed, if they are continue on with the script.

2b) When a driver / software gets installed and it needs to restart, restart the system and continue where the driver / software left off.

The purpose for this script(s) is to get the entire collection of Hardware IDs and Device IDs of a system and write the output to a file so it can install motherboard drivers and software. Next, I need the script to read the output and if it makes a match with one of the IDs, install the appropriate driver / software.

While installing the drivers / software – for example the chipset drivers (this requires a restart), I need the system to restart. When it gets back into Windows, I need the script to start and continue where it left off(This is the scripts POV in my head-- Oh I just finished installing the Chipset driver, next on my list is Audio, let me continue installing the drivers/software)

I hope my goal makes sense to you all. To get the Hardware IDs and Device IDs, I downloaded and imported this module – https://gallery.technet.microsoft.com/scriptcenter/Device-Management-7fad2388 <------- Are there built in commands I can run to get the same output without loading a module?

Hmmm … for how many different devices do you want to do that? Usually in an enterprise environment there is a limited amount of different hardware types and they can be provided with a prepared set of drivers.

We (my company) uses many different vendors for motherboards (ASUS, GIGABYTE, MSI, ASROCK, and Laptops)

Why don’t you want to use the module?

PowerShell functionality is delivered by modules.

Get-CimInstance -ClassName Win32_PnPDevice or Get-WmiObject -Class Win32_PnPDevice might deliver what you’re looking for.

Now, To match the hardware id’s with the drivers, to me seems like the easiest part. How would I delegate the install process? How would I continue where I left off after a restart?

You’ll need to create a task list that includes a status (Not started, rebooting, complete, etc) and store it in a file. Then you can pick up at the next step when the script restarts. You’ll probably need to create a scheduled task that runs after startup to kick off the script each time.

Is there a good tutorial on this? This seems confusing to me

If you have PoweShell v 3.0 or Higher, better go through below article which may help you in Restarts.

https://technet.microsoft.com/en-us/library/jj149010.aspx

Thanks,
kvprasoon

The Internet is full of tutorials and even prewritten scripts you could adapt to your needs. Here you have some starting points: Beginner Sites And Tutorials, Microsoft Technet Script Gallery.

And you might review the Microsoft Deployment Toolkit (MDT). It’s free and it’s made for deployment scenarios.

Can someone tell me if I am doing this wrong? Am I allowed to create a scheduled job and call the next workflow below it on the next startup?

workflow Install-Chipset {
        Start-Process C:\Chipset\Setup.exe -ArgumentList "-s"
}

$AtStartup = New-JobTrigger -AtStartup

Register-ScheduledJob -Name Chipset -Trigger $AtStartup -ScriptBlock { Install-Audio }

Restart-Computer

workflow Install-Audio {
        Start-Process C:\Audio\Setup.exe -ArgumentList "-s"
}

Anyone?

Hi Justin,

Wworkflows has the ability to continue on restarts and is the main advantage of using it. Scheduled jobs are not required here.
You could please go through below Blog post by Richard.
https://blogs.technet.microsoft.com/heyscriptingguy/2013/01/23/powershell-workflows-restarting-the-computer/

regards,
kvprasoon

@kyprasoon

That article was a good read. I followed it and I am still having issues. When I first run the work flow , the system will restart, everything seems good. When I log back in, the job is still suspended even though I tell it to resume on logon. Below is a copy of my code:

Workflow Install-Chipset {
    Start-Process Notepad.exe

    Restart-Computer -Wait
    
    Get-Process | Out-File c:\test.txt

    }

    $action = '-NonInteractive -NoLogo -WindowsStyle Normal -NoProfile -NoExit -Command "&"C:\psworkflow.ps1"'
    $pstart = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    Get-ScheduledTask -TaskName Install | Unregister-ScheduledTask -Confirm:$false
    $act = New-ScheduledTaskAction -Execute $pstart -Argument $action
    $trig = New-ScheduledTaskTrigger -AtLogOn

    Register-ScheduledTask -TaskName Install -Action $act -Trigger $trig -RunLevel Highest

    Install-Chipset 

This is what I run in the “psworkflow.ps1” file at logon:

Import-Module PSWorkflow
Get-Job | Resume-Job

Still you miss the point of Workflows, No need of using Scheduled tasks wen we have workflows.
I’m sure you will be able to make it, adding one more reference , must read and try and implement it in your way for your task

https://blogs.msdn.microsoft.com/powershell/2013/12/23/automatically-resuming-windows-powershell-workflow-jobs-at-logon/

regards,
kvprasoon

I still cannot get it to resume on it’s own. I always have to manually type it in powershell. When I go to the task scheduler and right click run, it will not perform the task.

I am also in Audit mode with sysprep. I don’t see this being an issue.

Can anyone please help me out? I cannot get my job to resume after logging on after a restart