I've been using arrays lately and really missing Python's "in" operator.
e.g.:
if ("hello" in ["hello", "there", "sup"]):
print "this prints :)"
I've made up for it a little bit by creating a "ThereExists-Object" function, like so:
function ThereExists-Object([System.Management.Automation.ScriptBlock] $sb)
{
return ($input | where $sb) -as [bool]
}
New-Alias -Name ThereExists -Value ThereExists-Object
e.g.:
if ($arrayOfStuff | thereexists { $_ -eq "hello" } )
{
write-host "this prints too"
}
obviously I could define another function for this as well... but I'd like to know if there's some syntactical sugar that I'm unfamiliar with that could get this job done.
So... is there any?
PowerShell is a commandline user interface for Windows that is often used as part of a Python programmer's development environment. PowerShell is an implementation of the shells concept. Learn more in the development environments chapter or view the table of contents for all topics.
Python is an interpreted high-level programming language whereas PowerShell provides a shell scripting environment for Windows and is a better fit if you choose to automate tasks on the Windows platform.
Array subexpression operator @( )Returns the result of one or more statements as an array. The result is always an array of 0 or more objects. PowerShell Copy.
With your PowerShell command line open, enter python to run the Python 3 interpreter. (Some instructions prefer to use the command py or python3 , these should also work). You will know that you're successful because a >>> prompt with three greater-than symbols will display.
$arrColors = "blue", "red", "green", "yellow", "white", "pink", "orange", "turquoise"
$arrColors -contains "black"
False
$arrColors -contains "blue"
True
source: http://technet.microsoft.com/en-us/library/ee692798.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With