Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
using
Last Post 31 Aug 2010 07:48 AM by
thanosazlin
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
thanosazlin
New Member
Posts:19
30 Aug 2010 01:58 PM
powerhsell nube here, i can't figure out why my if statement works but the switch statement does not? aren't they both doing the same thing?
the $input variable has some lines in it that contain smiliar to the following:
Pseudo name=harddisk8
i'm trying to strip away the "Pseudo name=" part of the string. it works for my if statement but i tried it in a switch statement and it just outputs the line with the "Pseudo name="
foreach ($line in $input)
{
[string]$test = $line
switch ($test)
{
$test.Contains("Pseudo name"){$test = $test -replace "Pseudo name=",""} }
$test
#if ($test.Contains("Pseudo name")){
#$test = $test -replace "Pseudo name=",""
#}
#$test
}
Marco Shaw (MVP)
Veteran Member
Posts:1642
30 Aug 2010 04:24 PM
I'm sorry, I think you aren't using switch properly. Consider this example:
$test="Pseudo name=foo"
switch -regex ($test){
"Pseudo name=*" {$_.replace("Pseudo name=","")};;
}
I think that does what you want. You might be over-complicating things by using a switch unless you're going to be doing several conditions.
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com
thanosazlin
New Member
Posts:19
31 Aug 2010 07:48 AM
thanks that worked . yeah i was just testing switch with 1 entry first :). what are the 2 ;; for by the way?
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2