?
Solved

Pass file as parameter to powershell script

Posted on 2014-12-02
2
Medium Priority
?
962 Views
Last Modified: 2014-12-07
Is it possible to pass a file to a powershell script as parameter, so that I will run the script as below ? Tks

.\myshut.ps1  List1.csv

Import-CSV .\computer1.csv | ForEach-Object{
stop-computer -Computer $_.Name -Force -ErrorAction silentlycontinue}
0
Comment
Question by:AXISHK
[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
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 40477946
Param(
	[Parameter(Mandatory=$True)]
	[string]$Path
)
If (-Not (Test-Path -Path $Path)) {
	"File '$Path' not found!" | Write-Error
	Exit 1
}
Import-CSV -Path $Path | ForEach-Object {
	Stop-Computer -Computer $_.Name -Force -ErrorAction SilentlyContinue
}

Open in new window

0
 

Author Closing Comment

by:AXISHK
ID: 40485979
Tks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

777 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