Solved

Pass file as parameter to powershell script

Posted on 2014-12-02
2
443 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
2 Comments
 
LVL 83

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

15 Experts available now in Live!

Get 1:1 Help Now