Solved

powershell switch statement

Posted on 2014-04-16
3
370 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 83

Assisted Solution

by:oBdA
oBdA earned 250 total points
ID: 40003713
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
ID: 40004002
Correct. "If in doubt, check $_ out" ;-).
0
 

Author Comment

by:Kay
ID: 40004161
ohh ok thanks
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

932 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

10 Experts available now in Live!

Get 1:1 Help Now