?
Solved

Run an executable with a passed variable using PowerShell

Posted on 2013-01-22
3
Medium Priority
?
259 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 2000 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 71

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

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Screencast - Getting to Know the Pipeline

807 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