Author Posts

November 17, 2016 at 1:06 am

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?

November 17, 2016 at 9:39 am

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.

November 17, 2016 at 3:44 pm

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

November 17, 2016 at 3:46 pm

Why don't you want to use the module?

PowerShell functionality is delivered by modules.

November 17, 2016 at 4:00 pm

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

November 17, 2016 at 4:44 pm

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?

November 17, 2016 at 5:01 pm

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.

November 17, 2016 at 5:02 pm

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

November 17, 2016 at 5:03 pm

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

November 17, 2016 at 7:01 pm

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.

November 18, 2016 at 1:43 am

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"
}

November 19, 2016 at 8:10 am

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

November 21, 2016 at 3:39 pm

@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

November 21, 2016 at 4:16 pm

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

Automatically resuming Windows PowerShell Workflow jobs at logon

regards,
kvprasoon

November 21, 2016 at 4:57 pm

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.

November 28, 2016 at 5:30 pm

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