Can you please provide me a way in powershell to declare collection List from type keyvaluepair, and the way to add elements from this type. Is not acceptable to use Hashtable, it is necessary to use List of this type.
Thanks in advance.
I'm not sure what's stopping you from just going ahead and creating such a list.
$list = New-Object 'System.Collections.Generic.List[System.Collections.Generic.KeyValuePair[KeyType,ValueType]]'
Related
I have a few questions about the following code.
Get-DBAAgentJob -SqlInstance *instancename* | Where-Object { $_.HasSchedule -Match "False" }| Out-GridView
In the Where-Object, there is $.HasSchedule. What is '$.HasSchedule'? I looked in the help for Where-Object and online and I don't understand what that is. Is it a function?
What does this syntax signify/do $_ ?
What all can I filter for in Where-Object other than .HasSchedule? Also,where I can find out how to figure that out please? If it's not in help or books online or a google search, I'm not sure. My google search algorithm is probably not good enough to get me in the ballpark.
I'm curious what are all the things I can filter on in the Where-Object in this line of code. For example, instead of has schedule, if I wanted to look where the job is not enabled, is there a .NotEnabled?
Thanks for the help.
The Where-Object clause is a way to filter objects returned from a cmdlet on a certain property.
In your example, it is filtering objects on the HasSchedule property. The example's filter says this property needs to be False in order for the objects to get piped through the pipeline where the next cmdlet takes them as input.
It tests the objects using the $_ Automatic variable, which represents each object in sequence that is coming in from the Get-DbaAgentJob cmdlet.
Usually, to find out what an object would look like, you can simply google for it.
In this case, if you look for Get-DBAAgentJob, you will find this page, where you can look at the function itself.
Here you can find what properties each returned object has:
ComputerName, InstanceName, SqlInstance, Name, Category, OwnerLoginName, IsEnabled, LastRunDate, DateCreated, HasSchedule, OperatorToEmail.
As you can see, there is a property IsEnabled, so you can filter on Not enabled with
Where-Object { -not $_.IsEnabled }
See: PowerShell Logical Operators
If you click the home page for dbatools you'll fine a section called docs where you can learn more.
Browse for free ebooks on PowerShell
Hope that helps
In case someone finds this useful in the future, #Theo's answer was helpful in giving me the base understanding of my question.
I learned more on this today and I will post it to help others in the future.
To answer my question:
The .hasSchedule is one of the many properties of Get-DBAAgentJob.
The . 'dot'. "The most common way to get the values of the properties of an object is to use the dot method." Books Online (BOL)
"All Properties and Methods for a given object are called members... Help files for any given command do not tell you what kinds of objects, properties, and methods are available, the only way to tell is to use the Get-Member' cmdlet. Learning PowerShell Jonathan Hassall
This code will tell you all of the properties and methods for a member, in this case the one I was interested in learning more about.
Get-DBAAgentJob -SqlInstance instancename | get-member
This shows me all the properties and methods available, including hasSchedule and isenabled
BOL: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_properties?view=powershell-7
Where can I find detailed documentation for the properties of the objects returned by Get-SPOSite in PowerShell? According to the type information header created by Export-Csv, they are of type Microsoft.Online.SharePoint.PowerShell.SPOSite. I'm looking specifically for information on the meaning of each of the properties.
It's good practice to use debug tool(I use PowerGUI Script Editor for PowerShell Script debug) to check the object usually.
I've gotten to a point in working with Powershell that I don't need to have a book or reference manual by my side for most tasks. I still have to search here or MSDN from time to time but it is far less frequent nowadays.
A lot of information on Powershell is readily available but you just need to know where to look. And this is where I am stuck.
What I want to do is list all acceptable property values for a given object without having to pull up the MSDN documentation (which is dryer than insulated ceiling tiles). Don't misunderstand me here; I'm not asking to list current or default properties for an object, I just want to list a property of an object and see what options I have available.
Here is an example of what I am not talking about:
New-Object System.Diagnostics.ProcessStartInfo "PowerShell" | gm
or:
(New-Object System.Diagnostics.ProcessStartInfo "Powershell").FileName
Those second one queries the current or default value for that particular named property. The first one will list a table with Name, MemberType, and Definition. Definition will give the type, handle, parameters, and\or {get; set;} (depending on whether the MemberType is a method, property, event, etc).
Say I would like to set that particular property--how do I know what values are valid and which are not?
What I am talking about would be something along these lines:
(New-Object Windows.Forms.Form).FormBorderStyle | gm
or:
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle | gm
For the FormBorderStyle, valid assignable values are: None, FixedSingle, Fixed3D, FixedDialog, Sizable, FixedToolWindow, or SizableToolWindow. The only way I found these was through an the text rendered during an exception. How would I go about finding those values without having to rely on exceptions?
Ideally, I don't want to have to keep searching MSDN, TechNet, or StackOverflow. Is there a cmdlet or query that I can use within Powershell (outside of get-help or man) to give me that information? Get-Help\man aren't very useful when it comes to a smaller and more defined scope.
Without saying "Google it", "RTFM", or "get good", what advice do you all have?
Thanks.
In this specific case, FormBorderStyle is an enum, so this will work:
[enum]::getvalues((New-Object Windows.Forms.Form).FormBorderStyle.gettype())
Quick note: my sentence does not imply that this will not work in other cases. The same syntax is valid for any enum.
Credit to #TheMadTechnician, another possible syntax:
[Windows.Forms.FormBorderStyle].GetEnumNames()
It's also possible to combine both, if you can't bother to look up the enum's name:
(New-Object Windows.Forms.Form).FormBorderStyle.gettype().GetEnumNames()
I have 7 variables called averageMon, averageTue, averageWed, and so on, and I need to compare the value stored in each variable to see which holds the highest value. I've been looking around but haven't found a way to do this. I'm brand new to this, and I'm sure this is a simple question, but any help would be appreciated. Thanks!
If I understand correctly, just call the max function:
max(averageMon, averageTue, averageWed, averageThu, averageFri, averageSat, averageSun)
http://swift-ios.co/standard-functions-in-swift/
I want to compare a url to a specific path to see if they match. I have tried so many variations and just can't get it to work, the two items I need to use are
{%CurrentDocument.RelativeURL.Replace("~","")%}
and
{&/{0}/{1}/{2}|(tolower)&}
In the current test scenario, both of these return the same string, however, when I put them together
{%CurrentDocument.RelativeURL.Replace("~","")|(equals){&/{0}/{1}/{2}|(tolower)&}|(truevalue)yes#%}
I get a false result displaying, I'm pretty positive it's because I can't nest a path expression inside an expression but not sure if there is another way? Any help would be appreciated.
Thanks
According to the documentation you should be able to substitute path macro with {%Path.path%}. Then there is no need to nest different types of macros but use the Path the same way as CurrentDocument.