Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Run an executable with a passed variable using PowerShell

Posted on 2013-01-22
3
252 Views
Last Modified: 2013-01-30
Hello. I have a command that I would like to run. The command requires a parameter. I have added the parameter to a text file. Using PowerShell, I know how to read the text file and output what is it in but but cannot figure out how to pass it to the executable. Below is the command and my script so far. Could anyone point me in the right direction for executing the command with the parameter using PowerShell? Thank you for any assistance.

The text file contains Windows Features that I would like to remove online using DISM. It contains items like MediaCenter, Chess, etc.

Command
DISM /online /Disable-Feature /FeatureName:<<parameter from text file>>

Script so far
$Cleanup = "E:\Features\Removal.txt"
Get-Content $Cleanup | Foreach-Object {Write-Host $_}
0
Comment
Question by:Lorrec
3 Comments
 
LVL 14

Accepted Solution

by:
athomsfere earned 500 total points
ID: 38806434
Here is a function in Powershell I use for SQL installs.

function sql08R2($a)
	{
	Write-Host $a
	$Installer = "R:\MS SQL Server 2008 R2 Standard\setup.exe"
	$Argus = '/Q /ConfigurationFile="R:\2008R2Conf.ini"'
	Write-Host $Argus
	Start-Process -FilePath $Installer -ArgumentList $Argus -Wait -PassThru
	Write-Host "2008 R2 Installed"
	}

Open in new window


The Start-Process is what calls the application, -wait tells the script to not move on until the install is done.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 38806591
Get-Content $Cleanup |
  Foreach-Object { DISM /online /Disable-Feature /FeatureName:$_ }

Open in new window

should do that.
0
 

Author Closing Comment

by:Lorrec
ID: 38835185
Thank you for the assistance.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Want to Create New-GlobalAddressList 2 13
Customizing XML with Powershell 2 20
BATCH to EXE Converter 2 32
Nested ForEach in Powershell 4 13
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
A brief introduction to what I consider to be the best editor for PowerShell.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question