locked
How do I get this expression to evaluate False? RRS feed

  • Question

  • I have this piece of code in my script.  It is evaluating as True even though (by my understanding), it should evaluate as False.  Can someone explain what I am doing wrong, and how to fix it.  

    $port = '172.27.1.79'
    if ($port.substring(0,3) = 'IP_') { 
    write-host 'True'
    } else {
    write-host 'False'
    }

    Thanks you!

    Terry

    Thursday, October 24, 2019 4:03 PM

Answers

  • In PowerShell the "=" is not used for testing. It is only used for assignment so you are trying to assign the value.

    Use "-eq" instead.

    help about_operators

    To test strings use "-match" as it is more direct and flexible.

    if ($port -match  '^IP_') { 


    \_(ツ)_/

    • Marked as answer by TBone69 Thursday, October 24, 2019 5:00 PM
    Thursday, October 24, 2019 4:29 PM

All replies

  • In PowerShell the "=" is not used for testing. It is only used for assignment so you are trying to assign the value.

    Use "-eq" instead.

    help about_operators

    To test strings use "-match" as it is more direct and flexible.

    if ($port -match  '^IP_') { 


    \_(ツ)_/

    • Marked as answer by TBone69 Thursday, October 24, 2019 5:00 PM
    Thursday, October 24, 2019 4:29 PM
  • Oh, I see!  Thank you!


    Thursday, October 24, 2019 4:59 PM


  • 大台灣小妹送茶性感女神外送辣妹
    服務時間:早上10點至凌晨2點左右
    台灣純本土兼職正妹喔(想瞭解更多久快快加小蠻腰帳號喔)
    ◆→賴q8778或593654即時→即時/sk:xc7794
    請直接告知,您預算喜歡條件類型需求 會幫您安排 不喜歡可以換
    所以您和小蠻腰姐姐聯絡時,請儘量說明您的需求.預約,避免造成大家的不愉快
    有照片的都要提早2小時~3小時前預約
    喜歡怎樣類型的MM?: 嬌小/高挑/可愛/甜美/清純/氣質/艷麗/青熟
    (或者可以指定要 某位妹妹)
    建議多挑幾位?例如第一人選,第二人選,第三人選
    想約的時間 地點(旅館飯店) 您靠近哪就約附近比較方便
    服務務地區:台北/台中/高雄/新竹/彰化/南投
    第一次合作的客人要先開好房間的喔.成為小妹家的熟客可送住家外送到府的喔.
    特別推薦小妹色群下載註冊網址:https://telegram.org?
    註冊軟件: Twitter 加色群聊天群客服帳號:ok5920
    Twitter中文版:https://t.me/setlanguage/taiwan
    ☆【全台灣約妹網】www.ny076699.com
    ☆【全台灣約妹網】www.ny076699.com
    重點#小妹貼心提醒:各地區沒有服務的地區→→→有服務地區
    1.屏東找外約方便來→→→→→→→高雄 台南 
    2.中壢桃園找外約方便來→→→→→林口.龜山.萬壽路
    3.基隆找外約方便來→→→→→→ →台北 南港  汐止
    4.花蓮找外約方便來→→→→→→→ 台北  南投  台中  彰化
    5、嘉義找外約方便來→→→→→→→台南 彰化  高雄
    6、樹林找外約方便來→→→→→→→板橋  土城
    7、苗栗找外約方便來→→→→→→→新竹
    8、三峽找外約方便來→→→→→→→土城
    9、宜蘭找外約方便來→→→→→→→台北
    10.安平區找外約方便來→→→→→→中西區
    11.新市區找外約方便來→→→→→→永康區
    12.橋頭市找外約方便來→→→→→→楠梓區
    13.大寮區找外約方便來→→→→→→小港區  鳳山區
    14.台東找外約方便來→→→→→→→高雄  
    #小妹貼心提醒:禁止未滿十八小朋友【禁止加賴】發現一律封鎖####
    Thursday, October 24, 2019 5:01 PM