Solved

powershell switch statement

Posted on 2014-04-16
3
377 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
[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
3 Comments
 
LVL 84

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 69

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

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