Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Run an executable with a passed variable using PowerShell

Posted on 2013-01-22
3
Medium Priority
?
258 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
[X]
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
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

618 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