Solved

Pass file as parameter to powershell script

Posted on 2014-12-02
2
716 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 84

Accepted Solution

by:
oBdA earned 500 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…

726 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