13 Replies Latest reply on Jan 22, 2018 9:29 AM by BC

    Run powershell and DISM in OS provisioning

    jhedelin Apprentice

      Hi there,

       

      Im currently working on Deploying my Windows 10 Enterprise.

      I need to use powershell to Import a default startmenu to my users.

      I need to use dism to import Default Application Associations.

       

      But i cant get it to work!

       

      All these steps are under System Configuration in OS provisioning.

       

      First i set powershell execution policy to bypass

      Target filename:

      C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

      Command Line:

      Set-ExecutionPolicy bypass -force

       

      SUCCESS

       

      Then i want to import my Startmenu.xml

       

      Target filename:

      C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

      Command Line:

      Import-StartLayout -LayoutPath C:\Winsrc\StartMenu.xml -MountPath C:\

       

      I get this message:

       

      Import-StartLayout : The term 'Import-StartLayout' is not recognized as the nam

      e of a cmdlet, function, script file, or operable program. Check the spelling o

      f the name, or if a path was included, verify that the path is correct and try

      again.

      At line:1 char:1

      + Import-StartLayout -LayoutPath C:\Winsrc\StartMenu.xml -MountPath C:\

      + ~~~~~~~~~~~~~~~~~~

          + CategoryInfo          : ObjectNotFound: (Import-StartLayout:String) [], 

         CommandNotFoundException

          + FullyQualifiedErrorId : CommandNotFoundException

       

       

      If i try to open powershell on the machine im deploying Win10 and type:

       

      Import-StartLayout -LayoutPath C:\Winsrc\StartMenu.xml -MountPath C:\

       

      It works perfect...

       

      When i Use DISM

      Target filename:

      C:\Windows\System32\dism.exe

      Command Line:

      /online /Import-DefaultAppAssociations:C:\Winsrc\DefaultApps.xml

       

      I get this message:

       

      Deployment Image Servicing and Management tool

      Version: 10.0.10586.0

      Error: 11

       

      You cannot service a running 64-bit operating system with a 32-bit version of DISM.

      Please use the version of DISM that corresponds to your computer's architecture.

       

      The DISM log file can be found at C:\Windows\Logs\DISM\dism.log

       

      If i open cmd on the machine im deploying Win10 and type:

       

      C:\Windows\System32\dism.exe /online /Import-DefaultAppAssociations:C:\Winsrc\DefaultApps.xml

       

      It works perfect...

       

      What am im doing wrong here?! Please help!!

       

      Regards

      Johan

        • 1. Re: Run powershell and DISM in OS provisioning
          jhedelin Apprentice

          I have also tried to do a Software Distribution with powershell ... not WORKING.. how hard can it be to run a simple .PS1 file?

          • 2. Re: Run powershell and DISM in OS provisioning
            JoeDrwiega SupportEmployee

            For the powershell in provisioning try executing it all in one line: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Set-ExecutionPolicy bypass -force Import-StartLayout -LayoutPath C:\Winsrc\StartMenu.xml -MountPath C:\

            I have used this execution in the past.

             

            For dism have you tried using the C:\Windows\SysWOW64 version of these tools? or try like I stated above to execute the full string: C:\Windows\System32\dism.exe /online /Import-DefaultAppAssociations:C:\Winsrc\DefaultApps.xml

             

            For SWD if you use it are you checking the box for 64bit?

            • 3. Re: Run powershell and DISM in OS provisioning
              Squonkie Apprentice

              I have had this exact issue with DISM. To get it to run as apart of a provisioning sequence you need to change the command c:\windows\sysnative\dism.exe


              The command you are using runs fine from a batch file but not as part of a task.

               

              Hope that helps

              • 4. Re: Run powershell and DISM in OS provisioning
                jhedelin Apprentice

                Ok, i tried to runt dism in a .cmd file

                 

                C:\Winsrc\DefaultApps.cmd

                Same error.

                 

                c:\windows\sysnative\dism.exe

                Does not exist.

                 

                /Johan

                • 5. Re: Run powershell and DISM in OS provisioning
                  jhedelin Apprentice

                  C:\Windows\SysWOW64 (contains 32bit versions) im installing 64bit Windows.

                   

                  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Import-StartLayout -LayoutPath C:\Winsrc\StartMenu.xml -MountPath C:\

                  Does not work....

                  • 6. Re: Run powershell and DISM in OS provisioning
                    Rookie

                    I couldn't get the PowerShell Import-StartLayout to work either... so I cheated.

                     

                    I put my exported start menu XML on a UNC share and renamed it to LayoutModification.xml.

                     

                    In my provisioning template, I use a "connect to resource" where the XML is stored.

                     

                    I then use the  "Copy file" action and put the XML in "C:\Users\Default\AppData\Local\Microsoft\Windows\Shell"

                    Example: C:\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml

                     

                    After imaging all users that log into the computer will get this start menu.

                     

                    For future changes of the start menu, I will need to target the XML using policy preferences to overwrite the file etc..

                     

                    Let me know if you have any questions!

                    • 7. Re: Run powershell and DISM in OS provisioning
                      jhedelin Apprentice

                      Yes, i also cheated...

                      I deployed my Windows 10 template, installed my default app association with DISM, installed default startmenu with powershell and then made a new image for deployment.

                       

                      I dont like this, but i dont have time to try more powershell in my OS provisioning for now...but it is REALLY annoying when you can not run powershell in provisioning, this is something LANDESK have to improve...

                      • 8. Re: Run powershell and DISM in OS provisioning
                        Rookie

                        I need to keep my image as clean as possible, so I had to use the method I described above.

                         

                        We use the same image for Labs, Classroom, and Staff (University Environment).

                         

                        I have another PowerShell that removes all windows store applications (Candy Crush, Xbox etc.) I had issues with, and ended up having to use "Distribute Software" during provisioning and changing the Account setting to run-as logged in.  The PowerShell had to run as the context of a user... not system which might also be the same case for the Import-StartLayout.  I will test this morning and let you know if it works.

                         

                        PowerShell is tricky to get the case correct, so I don't believe this is a "LANDesk Issue" exactly.

                        • 9. Re: Run powershell and DISM in OS provisioning
                          jhedelin Apprentice

                          Best practice is always to keep the image as clean as possible so your doing it all right!

                          I will try to run the powershell wih logged in user... or just copy the file to (C:\users\default.....)

                           

                          And the DISM with default app associations could be deployed the GPO instead.

                          • 10. Re: Run powershell and DISM in OS provisioning
                            Rookie

                            I got the Start-Import to work via a "Distribute software" action during provisioning.

                             

                            Here is what I did...

                             

                            Important:

                            Make sure you have an agent installed before running this task, otherwise it can't run as LocalSystem to run the commands.

                            I created a simple provisioning agent so I have full control of the box, right after first boot.

                             

                            I am also testing via a domain joined computer, if the system isn't joined to the domain yet you will probably need to map the resource before running the "Distribute software"

                             

                            Powershell Code (all up to you if you want to use try-catch but I like getting feedback)

                            I had issues when trying to import from a UNC path, so I copy the file local before importing...

                             

                            $XML = '\\servername\scripts\LayoutModificationLabs.xml'

                            $DefaultLayout = 'C:\DefaultLayout.xml'

                             

                            try

                            {

                                Copy-Item -Path $XML -Destination $DefaultLayout

                                Import-StartLayout -LayoutPath $DefaultLayout -MountPath c:\

                                Remove-Item $DefaultLayout

                            }

                            catch

                            {

                                $_.Exception.message | Out-File "c:\StartMenuImport.txt"

                                Write-Host $_.Exception.message

                            }

                             

                            Create a Distribution Package

                            • Architecture options - System architecture
                            • Accounts - LocalSystem account

                             

                            Provisioning Template

                            • System Configuration
                              • Distribute software
                                • Select your distribution Package

                             

                            Let me know if you have success!

                             

                            I am excited to have this working for my environment, I was really struggling to use a cleaner method than a hack

                            • 11. Re: Run powershell and DISM in OS provisioning
                              jhedelin Apprentice

                              Made a Powershell distribution package following your instructions.

                              Created a scheduled task, installed it on a windows 10 machine for testing (not os provision)

                               

                              LANDESK returned SUCCESS, but... no LayoutModification.xml file in C:\Users\Default\AppData\Local\Microsoft\Windows\Shell

                               

                              and if i open log file C:\StartMenuImport.xml the output is:

                              The term 'Import-StartLayout' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

                              • 12. Re: Run powershell and DISM in OS provisioning
                                phoffmann SupportEmployee

                                That's easy enough to fix.

                                 

                                If you run the command in ISE for Windows 10, you'll be greeted with the following:

                                PS_ImportNeedsImporting.jpg

                                 

                                ... so you need to import the additional module into PowerShell in your script. That's easy enough to do. Add the following at the top of your script:

                                 

                                Import-Module StartLayout
                                

                                 

                                ... and you should be good .

                                 

                                <This sort of stuff is the primary reason why I strongly prefer using the ISE to edit & develop PowerShell scripts >

                                • 13. Re: Run powershell and DISM in OS provisioning
                                  BC Rookie

                                  When you test manually Powershell opens in 64-bit by default.

                                  The default for PS to run in Endpoint Manager is 32-bit, set package architecture to 64-bit and it seems to work. No extra code needed.

                                  1 of 1 people found this helpful