Solved

Run an executable with a passed variable using PowerShell

Posted on 2013-01-22
3
245 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
Comment Utility
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 68

Expert Comment

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

Open in new window

should do that.
0
 

Author Closing Comment

by:Lorrec
Comment Utility
Thank you for the assistance.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
A procedure for exporting installed hotfix details of remote computers using powershell
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now