Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

Start a PS script in PE Environment


  • Please log in to reply
4 replies to this topic

#1 Nezcroc

Nezcroc

  •  Avatar image
  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:04:46 PM

Posted 05 June 2021 - 09:37 AM

Hello all, Yeah, first post and it's to ask for advice.. What a newb xD

I have more than 15 years of IT experience, but more than almost none in programing ! :D

 

So, here it is :

 

I've manage to create a winPE, with PowerShell (supposedly) enable on it... But, it doen't run...

 

I go to the "C" drive of the computer to run it like so :

c:\windows\system32\Windowspowershell\v1.0\powershell.exe d:\script.ps1

I also tried :

c:\windows\system32\Windowspowershell\v1.0\powershell.exe -executionpolicy bypass d:\script.ps1

In fact, if a batchfile could do what the ps script could, that would be even better !

 

Here's the script "big lines"

1. ask for an input (done)

2. get mac (done)

3.export results to cvs file (done)

4. enable NIC (unsure)

5. reboot computer (done)

 

Note that all the "done" are in PS

 

thi is the PS Code :

Set-ExecutionPolicy AllSigned -Force
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$report = "$scriptPath\CMPMAC.cvs"

$hostname = Read-Host "Input Computer name"
$wmi = gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $env:COMPUTERNAME

$macAddress = $wmi.MACADDRESS
$macAddress = $macAddress[1]

if (!(test-path $report))
    {
    new-item -Path $scriptPath -Name CMPMAC.cvs -ItemType File -Force | Out-Null
    }

Add-Content -Value "$hostname,$macAddress" -Path $report -Force

Enable-NetAdapter -Name "E*"
#shutdown -s -r 0

Please Help me... (you are my only hope ?)


Edited by Nezcroc, 05 June 2021 - 11:33 AM.


BC AdBot (Login to Remove)

 


#2 Shplad

Shplad

  •  Avatar image
  • Members
  • 7,207 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Canada
  • Local time:04:46 PM

Posted 05 June 2021 - 10:40 AM

I probably don't have the skills to figure this out, but I don't see where you've

told us what the problem is. Does it throw an error? Leave you at a blinking

cursor? What happens?


- Use this to collect and post information about your PC hardware, software and configuration (Whether or not you have crashing).

 

Blue Screen of Death (BSOD) Posting Instructions - Windows 10, 8.1, 8, 7 & Vista

https://www.bleepingcomputer.com/forums/t/576314/blue-screen-of-death-bsod-posting-instructions-windows-10-81-8-7-vista/

 

 


#3 Nezcroc

Nezcroc
  • Topic Starter

  •  Avatar image
  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:04:46 PM

Posted 05 June 2021 - 11:32 AM

Well, Either in WinPE or WinPE_PS, powershell doesn't execute.

also, I've found out that, in the PE environment, the "getmac" easy solution isn't reconized.

 

So, my questions are these :

1. how to run a powershell script from a winPE environment OR

2. get a way to have the MAC address (pls, not ipconfig /all) in a batch

3. enable the NIC (assuming there's only the LAN) in a batch.



#4 Shplad

Shplad

  •  Avatar image
  • Members
  • 7,207 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Canada
  • Local time:04:46 PM

Posted 05 June 2021 - 01:11 PM

Well, my next Google search would be finding out

whether powershell is even supported under WinPE.

I don't know, as I only use it for recovery purposes.


- Use this to collect and post information about your PC hardware, software and configuration (Whether or not you have crashing).

 

Blue Screen of Death (BSOD) Posting Instructions - Windows 10, 8.1, 8, 7 & Vista

https://www.bleepingcomputer.com/forums/t/576314/blue-screen-of-death-bsod-posting-instructions-windows-10-81-8-7-vista/

 

 


#5 sflatechguy

sflatechguy

  •  Avatar image
  • BC Advisor
  • 2,770 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:46 PM

Posted 13 June 2021 - 01:33 PM

Have a look at this. There are things you'll need to do to prep the WinPE environment to use PowerShell.

 

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-adding-powershell-support-to-windows-pe

 

Based on the code snippet, you were trying to run a PowerShell script on the D: drive from the PowerShell executable on the C: drive. In the PowerShell script, you are setting the policy to AllSigned. And it appears the executionbypass flag isn't working or is being overriden by the policy set in the script when you try to use it. Maybe set that to RemoteSigned in the script.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users