Jump to content
Mrente413

Automate Power-shell Prompts

Recommended Posts

Posted (edited)

Hello all,

Im trying to write an automate script that will run the following power-shell script

md c:\\HWID
Set-Location c:\\HWID
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
Install-Script -Name Get-WindowsAutoPilotInfo
Get-WindowsAutoPilotInfo.ps1 -OutputFile AutoPilotHWID.csv

I was wondering what the best way of going about having the Prompts that appear when going through to have [y] or [a] scripted to be input to continue the power shell process

This would be running as admin on multiple machines, will i need to be adding something like /a or -Force to my scripts in Automate.

 

Any help would be appreciated as im fairly new to power shell 🙂

Edited by Mrente413

Share this post


Link to post
Share on other sites

This is a little faster in execution (1 execution vs your 5 above) and safer (uses Execution Policy Bypass as a one-off temporary setting rather than as a system-wide change that could potentially remain open if a later command fails):

powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "Install-Script -Name 'Get-WindowsAutoPilotInfo' -Force; $PathToScript = (Get-InstalledScript -Name 'Get-WindowsAutoPilotInfo').InstalledLocation; Set-Location $PathToScript; .\Get-WindowsAutoPilotInfo.ps1 -?"

You will want to add a little more to this command to check to see if Get-WindowsAutoPilotInfo is already installed so that you can avoid forced redownloading of the script (unless that's what you want for every execution). Then modify the ending part to do your -OutputFile (and specify full path, i.e. -OutputFile 'C:\Windows\Temp\AutoPilotHWID.csv'). If you want, you can include

New-Item -Path 'C:\Windows\Temp\SomeDir123' -ItemType 'Directory';

to ensure that the folder you want the -OutputFile to save to always exists. You can also test to see if -OutputFile is capable on its own to automatically create the path if it does not already exist. If you really need to set the current directory for PowerShell, you can also insert this:

Set-Location 'C:\Windows\Temp\SomeDir123';

Lastly, forced redownloading of the script is not bad for consideration as it means any prior tampering of a pre-installed version of the script would be replaced by the genuine and latest untampered version of the script.

Edited by BlueToast
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...