Results 1 to 12 of 12
  1. #1
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts

    Windows PE & PowerShell

    Hey Y'all,

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

    https://technet.microsoft.com/en-us/.../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: dism.zip

    Has anyone had any luck with this procedure?

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  2. #2
    Lounger
    Join Date
    Dec 2009
    Location
    Gillingham, Dorset, UK
    Posts
    30
    Thanks
    0
    Thanked 13 Times in 11 Posts
    RG,

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

    Good luck

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Cliff,

    Once again "you're da MAN!"

    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!

    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!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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 "HKLM\WimPE" "$($WinPETemp)\Mount\Windows\System32\config\software"
    $RegPath = "HKLM:\WimPE\SOFTWARE\Microsoft\PowerShell\1\ShellIds" +
               "\Microsoft.Powershell\"
    $NIArgs = @{Path  = $RegPath 
                Name  = 'ExeutionPolicy' 
                Value = "RemoteSigned"
                PropertyType = 'DWORD'
                Force = $True}
    New-ItemProperty @NIArgs
    reg unload "HKLM\WimPE"
    Note: the above is run while the .wim file is Mounted.

    Of course this errors out, why else would I be posting , 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 CMsWinPESetup.zip 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!

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Super Moderator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    2,140
    Thanks
    101
    Thanked 579 Times in 464 Posts
    It looks like you have a typo: Name = 'ExeutionPolicy'

    Shouldn't the PropertyType be String, not DWORD? RemoteSigned is a string, after all.
    Last edited by Rick Corbett; 2016-04-24 at 17:12.

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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.

    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: HKLM\Software\Microsoft\PowerShell\V1.0\ShellIds\Mircosoft.Powershell
    In WinPE:      HKLM\WimPE\Microsoft\PowerShell\1\ShellIds\Microsoft.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 Users\Scripts 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?

    Last edited by RetiredGeek; 2016-04-24 at 17:28.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Hey Y'all,

    Seems there is always something!

    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      
    Running  RpcEptMapper       RPC Endpoint Mapper                   
    Running  RpcSs              Remote Procedure Call (RPC)           
    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?
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  8. #8
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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:
    1. You have already installed the Windows Assessment and Deployment Kit on your machine in the correct BITNESS!
    2. 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.

      MRCustomWIM.PNG
    3. You are familiar enough with PowerShell to create your own PS code or download utilities from the internet.
    4. 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:
    1. Run the utilities you loaded on the image, Ex:
      x:\Users\Utilities\HWiNFO64.exe
    2. Start PowerShell Ex:
      WindowsPowershell\V1.0\powershell.exe
      Note: navigation of the above command starts from the active directory which is x:\Windows\System32
    3. 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: CMsWinPESetup.zip

    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:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    Path   : G:\TempPE\Mount
    Online : False
    
    
    
        Directory: G:\TempPE\Mount\Users
    
    
    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.Core\Registry::HKEY_LOCAL_MACHINE\WimPE\
                      Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\
    PSParentPath    : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\WimPE\
                      Microsoft\PowerShell\1\ShellIds
    PSChildName     : Microsoft.PowerShell
    PSDrive         : HKLM
    PSProvider      : Microsoft.PowerShell.Core\Registry
    
    The operation completed successfully.
    
    
    LogPath          : C:\WINDOWS\Logs\DISM\dism.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:
    <#
     +--------------------------------------------------------+
     | Computer Mentors WinPe PowerShell CMD Profile          |
     |   04/20/2016 -                                         |                              
     +--------------------------------------------------------+
    #>
    
    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"
    
    <#--- Set Console Height/Width   ---
       Note: Set dimensions for the target machine or
             if to be used on more than one machine to
    		 the dimensions of the smallest screen!!!
    #>
    $ConSize = $Console.WindowSize
    $ConSize.Height     = 40   #Dell 1564 Laptop
    $ConSize.Width      = 120  #Dell 1564 Laptop
    $Console.WindowSize = $ConSize
    
    <#---  Set Other Console Colors   ---
    Available Color Names:
    	DarkBlue	DarkGreen		DarkCyan
    	DarkMagenta	DarkYellow		Gray
    	DarkGray	Blue			Green
    	Cyan		Red				Magenta
    	Yellow		White			DarkRed
    #>
    
    $Colors = $host.PrivateData
    $Colors.VerboseForegroundColor = "black"
    $Colors.VerboseBackgroundColor = "white"
    $Colors.WarningForegroundColor = "red"
    $Colors.WarningBackgroundColor = "yellow"
    $Colors.ErrorForegroundColor   = "white"
    $Colors.ErrorBackgroundColor   = "red"
    
    cd \Users\scripts
    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
    Last edited by RetiredGeek; 2016-05-02 at 14:23.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  9. The Following User Says Thank You to RetiredGeek For This Useful Post:

    wavy (2016-05-09)

  10. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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:
    1. $WinPETemp -- {set the same as in the WimPE creation program}
    2. $WinADK ------- {set the same as in the WimPE creation program}
    3. $CIArgs --------- {line 54 ... Set Path to the same value as $Destination in the WimPE creation program}

    Code:
    $WinPETemp = "G:\TempPE"
    $WinADK = "C:\Program Files (x86)\Windows Kits\10\" +
              "Assessment and Deployment Kit\" +
    		  "Windows Preinstallation Environment\amd64"
    
    $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        = "$WinAdk\Media" 
                Destination = $WinPETemp 
                Recurse     = $True
                Force       = $True}
    Copy-Item @CIArgs
    
    $NIArgs = @{ItemType = 'Directory'
                Path     = "$WinPETemp\Media\Sources" 
                Force    = $True}
    New-Item @NIArgs
    
    $CIArgs = @{Path        = "G:\Pewim\boot.wim" 
                Destination = "$WinPETemp\Media\Sources\boot.wim"}
    Copy-Item @CIArgs
    
    $WinPEKey = "$OSDrive" + ":\"
    
    $CIArgs = @{Path        = "$WinPETemp\Media\*" 
                Destination = "$WinPEKey"
                Recurse     = $True
                Force       = $True}
    Copy-Item @CIArgs
    
    & "$($env:windir)\system32\bootsect.exe" /nt60 "$WinPEKey"
    Make sure you change the items in BLUE to match those in the CMsWinPESetup.ps1 program!

    Program File: Create-Bootable USB Key.zip

    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.

    Produkey From WinPE.png

    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
    Last edited by RetiredGeek; 2016-05-09 at 16:56.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  11. The Following User Says Thank You to RetiredGeek For This Useful Post:

    RockE (2016-05-09)

  12. #10
    Silver Lounger wavy's Avatar
    Join Date
    Dec 2009
    Location
    ny
    Posts
    2,367
    Thanks
    233
    Thanked 147 Times in 136 Posts
    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 ??

    David

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

  13. #11
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Quote Originally Posted by wavy View Post
    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 !

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  14. #12
    Silver Lounger wavy's Avatar
    Join Date
    Dec 2009
    Location
    ny
    Posts
    2,367
    Thanks
    233
    Thanked 147 Times in 136 Posts
    Quote Originally Posted by RetiredGeek View Post
    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 !

    HTH
    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.
    David

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •