Solved

powershell switch statement

Posted on 2014-04-16
3
367 Views
Last Modified: 2014-04-16
Hi Guys,

I am constructing a switch argument in powershell and how do I get the "lndapp01" on the name variable?


switch ($vm)
    {
        "LNDAPP01" {

$name=
$computerName = Get-WmiObject Win32_ComputerSystem
$computername.rename("$name")

}

thank you in advance,
0
Comment
Question by:Kay
3 Comments
 
LVL 82

Assisted Solution

by:oBdA
oBdA earned 250 total points
Comment Utility
The usual "$_":
switch ($vm) { 
	"LNDAPP01" {
		$name = $_
		$computerName = Get-WmiObject Win32_ComputerSystem 
		$computername.rename($name)
	}
}

Open in new window

0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
Comment Utility
Correct. "If in doubt, check $_ out" ;-).
0
 

Author Comment

by:Kay
Comment Utility
ohh ok thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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