• Windows PE & PowerShell

    Home » Forums » AskWoody support » Windows » Windows 10 » Questions: Win10 » Windows PE & PowerShell

    Author
    Topic
    #505362

    Hey Y’all,

    I spent the better part of today trying to get this to work.

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

    However, there is no Love!

    FYI: I’m doing this on Win 10 Pro and I downloaded the Win 10 Deployment and Imaging Tools and changed all the 8.1’s to 10’s in the script.

    Initially I got Error: 2, then uninstall and reinstall, now I get Error: 3?

    Here’s my DISM.log file: 44258-dism

    Has anyone had any luck with this procedure?

    :cheers:

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!
    Computer Specs

    Viewing 8 reply threads
    Author
    Replies
    • #1561184

      RG,

      Try this link, which is for Win 10 and PS 5.

      Good luck

    • #1561243

      Cliff,

      Once again “you’re da MAN!” :clapping:

      That article gave me the base I needed but I did have some problems with it (which I worked around) and it required a restore of my C: to clean it up!

      I now have a PS script that will create the custom WIM file that I can feed to the Macrium Reflect create boot media function and I get PowerShell on my MR Boot disk! :thewave:

      I’ll clean up the code, and comment on the problems I had, and post it in a while.

      My next hurdle is getting a PS Profile into the WIM along with a .cmd file to get it started. I’d also like to copy some of my PS scripts into the WIM, although I found I can access them as long as my G: drive is accessible (doesn’t need restoring).

      It’s interesting that in the MR screen you click on the icon for the command prompt then start PowerShell and it starts right in the same window just the prompt and title bar change!

      Thanks again! :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1561292

      Hey Y’all,

      Ok, we’re making progress I have a working code base that successfully creates a Custom WinPE.wim file that makes PowerShell available.

      I’ve also figured out how to add a directory under Users for my PS script files and copy selected .ps1 files to it.

      Now I’ve reached a bit of an road block. I’m trying to modify the .win registry file to set the Powershell ExecutionPolicy to RemoteSigned.
      I’ve done quite a bit of googling on the topic and the best I can come up with is the following:

      Code:
      #--- Modify PowerShell Execution Policy in WIM Registry ---
      
      reg load "HKLMWimPE" "$($WinPETemp)MountWindowsSystem32configsoftware"
      $RegPath = "HKLM:WimPESOFTWAREMicrosoftPowerShell1ShellIds" +
                 "Microsoft.Powershell"
      $NIArgs = @{Path  = $RegPath 
                  Name  = 'ExeutionPolicy' 
                  Value = "RemoteSigned"
                  PropertyType = 'DWORD'
                  Force = $True}
      New-ItemProperty @NIArgs
      reg unload "HKLMWimPE"
      

      Note: the above is run while the .wim file is Mounted.

      Of course this errors out, why else would I be posting :lol:, telling me it can’t find the path in the registry.

      Any of you registry GURUS know what I’m doing wrong?

      FYI: here’s the full .ps1 file 44272-CMsWinPESetup if you want to get the complete picture. When I have this all worked out I’ll publish a complete commented help enabled version right here so stay tuned to the same Bat Channel!

      :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1561307

      It looks like you have a typo: Name = ‘ExeutionPolicy’

      Shouldn’t the PropertyType be String, not DWORD? RemoteSigned is a string, after all.

    • #1561311

      Rick,

      Thanks for the reply and “Right you are!” Unfortunately, I found those out before seeing your post. Good thing I’m having my cataracts done next month! 😆 The problems with “blindly” copying from examples w/o thinking. :angry:

      And to add on the top of that the registry keys in the WinPE.wim file aren’t in the same place as in normal windows!

      Code:
      Normal Windows: HKLMSoftwareMicrosoftPowerShellV1.0ShellIdsMircosoft.Powershell
      In WinPE:      HKLMWimPEMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell"
      

      I had to find that out by mounting the WinPE Image, Mounting the WinPE Registry Hive and then using Regedit Interactively. Boy was I surprised by what I found, it’s always an adventure!

      But, I now have a USB key that will Load the Macrium Reflect Boot Environment and if i click on the CMD Prompt Icon at the bottom left I get a command prompt that let’s me start Powershell with the ExecutionPolicy set to Remote signed. It also has a couple of my PS scripts loaded in the UsersScripts directory.

      It only took two days of futzing around but I’m there.

      Now If I can figure out how to get the CMD prompt to come up with non default fonts, sizes, fore & background colors?

      :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1561331

      Hey Y’all,

      Seems there is always something! :angry:

      I have PowerShell running in WinPE but seems I can’t do much with it as I keep getting “RPC Server Unavailable 0x800706BA”

      However Get-Services shows it’s running:

      Code:
      Status   Name               DisplayName                           
      ------   ----               -----------                           
      Running  BFE                Base Filtering Engine                 
      Running  CryptSvc           Cryptographic Services                
      Running  DcomLaunch         DCOM Server Process Launcher          
      Stopped  defragsvc          Optimize drives                       
      Running  DeviceInstall      Device Install Service                
      Running  Dhcp               DHCP Client                           
      Stopped  diagnosticshub.... Microsoft (R) Diagnostics Hub Stand...
      Stopped  DiagTrack          Connected User Experiences and Tele...
      Stopped  Dnscache           DNS Client                            
      Stopped  Eaphost            Extensible Authentication Protocol    
      Stopped  EFS                Encrypting File System (EFS)          
      Running  EventLog           Windows Event Log                     
      Stopped  gpsvc              Group Policy Client                   
      Running  hidserv            Human Interface Device Service        
      Running  IKEEXT             IKE and AuthIP IPsec Keying Modules   
      Stopped  KeyIso             CNG Key Isolation                     
      Stopped  LanmanServer       Server                                
      Running  LanmanWorkstation  Workstation                           
      Running  lmhosts            TCP/IP NetBIOS Helper                 
      Running  LSM                Local Session Manager                 
      Running  MpsSvc             Windows Firewall                      
      Stopped  MSiSCSI            Microsoft iSCSI Initiator Service     
      Stopped  Netlogon           Netlogon                              
      Stopped  Netman             Network Connections                   
      Stopped  NetSetupSvc        Network Setup Service                 
      Stopped  NlaSvc             Network Location Awareness            
      Running  nsi                Network Store Interface Service       
      Running  PlugPlay           Plug and Play                         
      Stopped  PolicyAgent        IPsec Policy Agent                    
      Running  Power              Power                                 
      Running  ProfSvc            User Profile Service                  
      Stopped  RasAuto            Remote Access Auto Connection Manager 
      Stopped  RasMan             Remote Access Connection Manager      
      [COLOR="#0000FF"]Running  RpcEptMapper       RPC Endpoint Mapper                   
      Running  RpcSs              Remote Procedure Call (RPC)           [/COLOR]
      Stopped  sacsvr             Special Administration Console Helper 
      Running  SamSs              Security Accounts Manager             
      Stopped  smphost            Microsoft Storage Spaces SMP          
      Stopped  SstpSvc            Secure Socket Tunneling Protocol Se...
      Stopped  svsvc              Spot Verifier                         
      Stopped  swprv              Microsoft Software Shadow Copy Prov...
      Running  SystemEventsBroker System Events Broker                  
      Stopped  TrustedInstaller   Windows Modules Installer             
      Running  UserManager        User Manager                          
      Stopped  vds                Virtual Disk                          
      Stopped  W32Time            Windows Time                          
      Stopped  WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se...
      Running  Winmgmt            Windows Management Instrumentation    
      Running  wmiApSrv           WMI Performance Adapter               
      

      I’ve already made a hole through the Windows Firewall, per google results, to no avail if it is even running in WinPE?

      Any Ideas? :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1561995

      Hey Y’all,

      Hope you didn’t think I’d forgotten about this but it took me a while to track everyting down.

      So here’s the code to create a Custom WIM (Windows Image File) for Windows PE.

      I’ve tried to make this code as easy to understand and more importantly customize what is included on the Boot Media.

      You’ll find 2 array variables one for PowerShell Programs and one for Utility Programs. You can just modify the contents of these variables to include the PowerShell scripts and your favorite Utility programs. Note that I’ve included BASE directories in the $CIArgs variables and then just fill out the paths in the arrays. So just modify as appropriate for the computer you are using to create the image.

      Assumptions:

        [*]You have already installed the Windows Assessment and Deployment Kit on your machine in the correct BITNESS!
        [*]This program does NOT create your bootable media! I’ll probably create that program shortly but I’ve been using Macrium Reflect to create its bootable media using the custom WIM created by this program as a base so I have a full emeregency bootable disk on a single bootable media.

        44352-MRCustomWIM

        [*]You are familiar enough with PowerShell to create your own PS code or download utilities from the internet.
        [*]The utilities (programs) you load into the Utilities directory are the same BITNESS as your Windows PE installation. WOW (Windows on Windows 64) is NOT supported in the 64 bit installation! If you try to run a 32 bit program on WinPE 64Bit you’ll get this message: ”The subsystem needed to support the image type is not present.”

      Usage:

      Once booted into this disk you get the Macrium Reflect user interface which has the Icon on the taskbar for a Command Window.

      From the command window you can:

        [*]Run the utilities you loaded on the image, Ex:
        x:UsersUtilitiesHWiNFO64.exe
        [*]Start PowerShell Ex:
        WindowsPowershellV1.0powershell.exe
        Note: navigation of the above command starts from the active directory which is x:WindowsSystem32
        [*]Once PowerShell is started (if you have loaded a profile pointing to your scripts) you can start your PS Scripts as follows:
        .scriptname.ps1

      Here’s the Program: 44351-CMsWinPESetup

      Sample Run from PS-ISE:

      Code:
          Directory: G:TempPE
      
      
      Mode                LastWriteTime         Length Name                          
      ----                -------------         ------ ----                          
      d-----        4/23/2016   6:27 PM                Media                         
      d-----         5/2/2016  12:23 PM                Mount                         
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      Path   : G:TempPEMount
      Online : False
      
      
      
          Directory: G:TempPEMountUsers
      
      
      Mode                LastWriteTime         Length Name                          
      ----                -------------         ------ ----                          
      d-----         5/2/2016   2:15 PM                Utilities                     
      d-----         5/2/2016   2:15 PM                Scripts                       
      The operation completed successfully.
      
      
      ExecutionPolicy : RemoteSigned
      PSPath          : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINEWimPE
                        MicrosoftPowerShell1ShellIdsMicrosoft.PowerShell
      PSParentPath    : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINEWimPE
                        MicrosoftPowerShell1ShellIds
      PSChildName     : Microsoft.PowerShell
      PSDrive         : HKLM
      PSProvider      : Microsoft.PowerShell.CoreRegistry
      
      The operation completed successfully.
      
      
      LogPath          : C:WINDOWSLogsDISMdism.log
      ScratchDirectory : 
      LogLevel         : WarningsInfo
      
      
      
          Directory: G:
      
      
      Mode                LastWriteTime         Length Name                          
      ----                -------------         ------ ----                          
      d-----        4/23/2016   6:32 PM                Pewim                         
      
      
      Program Elapsed Time: 00:05:24 with 0 error(s).
      

      Sample PowerShell Profile used:

      Code:
      
      Function Prompt {
      
          If (-NOT ([Security.Principal.WindowsPrincipal] `
                [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
                [Security.Principal.WindowsBuiltInRole] "Administrator"))
          {
            $AdminStatus = ""
          }
          Else
          {
            $AdminStatus = "Administrator:"
          }
      
         $host.ui.rawui.WindowTitle = "$AdminStatus PS $pwd"
         "PS> "
      }
      
      #--- Set Console Display Colors ---
      $Console = $host.UI.RawUI
      $Console.BackgroundColor = "Blue"
      $Console.ForegroundColor = "White"
      
      
      $ConSize = $Console.WindowSize
      $ConSize.Height     = 40   #Dell 1564 Laptop
      $ConSize.Width      = 120  #Dell 1564 Laptop
      $Console.WindowSize = $ConSize
      
      
      
      $Colors = $host.PrivateData
      $Colors.VerboseForegroundColor = "black"
      $Colors.VerboseBackgroundColor = "white"
      $Colors.WarningForegroundColor = "red"
      $Colors.WarningBackgroundColor = "yellow"
      $Colors.ErrorForegroundColor   = "white"
      $Colors.ErrorBackgroundColor   = "red"
      
      cd Usersscripts
      Clear-Host
      

      I’d be very appreciative of anyone with a 32 bit installation to give the script a whirl and let me know if it works correctly.

      Coming next a version with comment based help builtin…after I hear from someone with a 32bit system.

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1563076

      Hey Y’all,

      I’m back again…groan!

      As promised in post #8 I’ve now have running code that will create a WinPE boot USB key. If the code is created on a machine running UEFI/Secure Boot the resulting USB Key will boot on both UEFI Secure boot & Legacy hardware!

      NOTE: You have to run the previous code to create your custom WinPE image w/PS support BEFORE running this code!

      The code will present you with a list to select the target USB key WHICH WILL BE WIPED!

      Once wiped the drive letter for that USB key is no longer valid and the code will setup the drive with a letter of Z so make sure it didn’t start out there and that you have no other drives assigned to that letter!

      There are three variables that need adjusting:

        [*]$WinPETemp — {set the same as in the WimPE creation program}
        [*]$WinADK ——- {set the same as in the WimPE creation program}
        [*]$CIArgs ——— {line 54 … Set Path to the same value as $Destination in the WimPE creation program}
      Code:
      $WinPETemp = "[COLOR="#0000FF"]G:TempPE[/COLOR]"
      $WinADK = "[COLOR="#0000FF"]C:Program Files (x86)Windows Kits10" +
                "Assessment and Deployment Kit" +
      		  "Windows Preinstallation Environmentamd64[/COLOR]"
      
      $Disk= Get-Disk | Where-Object { $_.BusType -eq 'USB' } | 
                        Out-Gridview -passthru
      
      Get-Disk -Number ($Disk.number) | Get-Partition | 
        Remove-partition -Confirm:$false -ErrorAction SilentlyContinue
      
      $CDArgs = @{Number      = $Disk.Number
                  RemoveData  = $True
      			RemoveOEM   = $True
      			Confirm     = $False
      			ErrorAction = "SilentlyContinue"}  
      Clear-Disk @CDArgs
      
      $IDArgs = @{Number         = $Disk.Number
                  PartitionStyle = "MBR"
      			ErrorAction = "SilentlyContinue"}
      Initialize-Disk @IDArgs
      
      $OSDrive='Z'
      
      $NPArgs = @{DiskNumber     = $Disk.Number
                  DriveLetter    = "$OSDrive"
      			UseMaximumSize = $True
      			IsActive       = $True}
      $Partition = New-Partition @NPArgs
      
      $FVArgs = @{Partition          = $Partition
                  FileSystem         = "FAT32"
      			NewFileSystemLabel = 'WinPEPS'}
      Format-Volume @FVArgs
      
      
      $NIArgs = @{ItemType = 'Directory'
                  Path     = "$WinPETemp" 
                  Force    = $True}
      New-Item @NIArgs
      
      $CIArgs = @{Path        = "$WinAdkMedia" 
                  Destination = $WinPETemp 
                  Recurse     = $True
                  Force       = $True}
      Copy-Item @CIArgs
      
      $NIArgs = @{ItemType = 'Directory'
                  Path     = "$WinPETempMediaSources" 
                  Force    = $True}
      New-Item @NIArgs
      
      $CIArgs = @{Path        = "[COLOR="#0000FF"]G:Pewimboot.wim[/COLOR]" 
                  Destination = "$WinPETempMediaSourcesboot.wim"}
      Copy-Item @CIArgs
      
      $WinPEKey = "$OSDrive" + ":"
      
      $CIArgs = @{Path        = "$WinPETempMedia*" 
                  Destination = "$WinPEKey"
                  Recurse     = $True
                  Force       = $True}
      Copy-Item @CIArgs
      
      & "$($env:windir)system32bootsect.exe" /nt60 "$WinPEKey"
      

      Make sure you change the items in BLUE to match those in the CMsWinPESetup.ps1 program!

      Program File: 44422-Create-Bootable-USB-Key

      FYI: I’ve been messing around with adding programs to the custom image and from my testing the 64Bit NirSoft utilities work and with the use of the NirCmd.exe program you can even take screenshots in the WinPE environment. Note: I did write the shots to a second USB key which BTW is where I initially tested the utilities before loading them into the image.

      44421-Produkey-From-WinPE

      As you can see this can be handy if you are trying to get software keys from an unbootable C: drive via ProduKey’s File->Select Source->2nd option button. You can see the two versions of Windows & Office from my dual boot laptop.

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1563098

      RG
      I am looking forward to checking this out> Thanks!

      WOW (Windows on Windows 64) is NOT supported in the 64 bit installation! If you try to run a 32 bit program on WinPE 64Bit you’ll get this message:

      Should not that be 16 bit ??

      :cheers:

      🍻

      Just because you don't know where you are going doesn't mean any road will get you there.
      • #1563100

        RG
        Should not that be 16 bit ??

        Sorry but NO! If you setup your Win PE using the 64 bit Windows you can NOT run 32 Bit, or for that matter 16 Bit, programs in the WinPE environment since it does NOT support WoW64 (Windows {32 bit} on Windows 64 bit).

        Of course that means you have to search for programs that use 64 bit code. NirSoft provides their utilities in both 32 & 64 bit versions. However, SysInternals does not :angry:!

        HTH :cheers:

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

        • #1563104

          Sorry but NO! If you setup your Win PE using the 64 bit Windows you can NOT run 32 Bit, or for that matter 16 Bit, programs in the WinPE environment since it does NOT support WoW64 (Windows {32 bit} on Windows 64 bit).

          Of course that means you have to search for programs that use 64 bit code. NirSoft provides their utilities in both 32 & 64 bit versions. However, SysInternals does not :angry:!

          HTH :cheers:

          Ah see! So no real reason to run as 64 PE is there? 32 PE should provide everything but a bit more usable RAM.

          I hope to check this out the next rainy day , too nice out now 😀
          I will go with 32 bit PE.
          :cheers:

          🍻

          Just because you don't know where you are going doesn't mean any road will get you there.
    Viewing 8 reply threads
    Reply To: Windows PE & PowerShell

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: