I'm trying to use the VMWare PowerCLI v6.0 to do some automated things. I have found the installed and online version of the cmdlet documentation and for the most part it tells you very simple information about the commands, like the parameters, return types and what the cmdlet does.
I'm trying to find more complete documentation on this because the online documentation provided by VMWare doesn't list the exceptions that a particular cmdlet might throw and definitely doesn't properly describe the types and their properties. For example:
$org = Get-Org -Name "test"
$leases = $org.ExtensionData.Settings.GetVAppLeaseSettings()
$leases.DeploymentLeaseSeconds = 0
$leases.StorageLeaseSeconds = 0
$leases.DeleteOnStorageLeaseExpiration = $False
$leases.UpdateServerData()
The example code can be found all over the internet but there's no details on it at all, just a vague "This is how you X". I've searched and searched but I can't find any documentation on what type ExtensionData returns and absolutely no documentation on the method GetVAppLeaseSettings. It seems like as far as VMWare and their documentation is concerned, this function doesn't exist.
Does anyone know where I can find documentation that lists thrown exceptions for each cmdlet and what CLR types are returned in the ExtensionData properties?
UPDATE
I watched a Pluralsight video on PowerCLI and found that you can display the ExtensionData object type and properties by simply running
$obj.ExtensionData
You can also see all the methods available for that object by running
$obj.ExtensionData | Get-Member -MemberType method
The problem with this is that you need to be connected to an existing vCloud server and even though this lists the available properties and methods, it does not show any documentation for those properties or methods. Not to mention you would need to actually have an object created to be able to query these values, for example:
$org = Get-Org -Name "test"
$org.ExtensionData | Get-Member -MemberType method
In the above example, I need to be connected to the server and already have an organization created to be able to view its properties and methods.
I'm looking for the documentation on those properties and methods and it doesn't seem like that exists anywhere that I've searched.
EDIT
If you are down voting or voting to close, please provide me with feedback. This is a serious question and I have done a lot research into answering this myself before I posted it here.
With the help of Mathias in the comments, I've determined that there is no official documentation for this portion of the PowerCLI. The only way to get any kind of documentation is to use a tool like ILSpy or through the PowerCLI terminal itself by means of commands like GetType() and Get-Member
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'm coming from a unix background where I've written some scripts using bash and bourne. But I need to write some scripts using powershell and I'm having a hard time finding information.
For example, in *nix, I can do man bash and read all about how to use bash and I can do man some_command to read about a specific command. So far, I found some powershell equivalents like get-command to see all available commands, but getting and using objects is really confusing me.
For instance, I'm trying to create a new scheduled task using powershell and found some sample code here on SO. Here is a snippit:
$schedule = new-object -com Schedule.Service
$schedule.connect()
$tasks = $schedule.getfolder("\").gettasks(0)
$tasks | select Name, LastRunTime
foreach ($t in $tasks) {
foreach ($a in $t.Actions) {
$a.Path
}
}
I understand what this script is doing, but without experience how would I know to do the following:
Know to use new-object -com Schedule.Service
Know that this object has a .connect method
Know that this object has a .getfolder and .gettasks object
A lot of the code seems ambiguous to me, so where would I find out the above information natively using powershell?
So you found Get-Command. That's a good start it will show you the available cmdlets. There may be even more available after importing snapins/modules. Use Get-PSSnapin -Registered and Get-Module -ListAvailable to see additional modules that may be imported to give you even more cmdlets.
The nice thing about PowerShell is that the creators built in an alias system. One of the goals of it was to make it easier to learn PowerShell when you have a bash/DOS background. For example if you type man Get-Process it will give you the documentation for the Get-Process cmdlet. To see all documentation for it use man Get-Process -Full. man doesn't actually exist, it is an alias for Get-Help which has the same functionality as man on UNIX/Linux. You can use the Get-Alias cmdlet to show the registered alias' and their definitions.
The script you found is working with a COM object. You can tell because of the -com parameter that was used for New-Object (which is actually short for -ComObject). Unlike .NET objects, COM objects are not built in to PowerShell however PowerShell has support for them the same way VBScript has support for them. The Get-Member cmdlet will unveil both .NET and COM type object members (properties and methods). More about Get-Member below.
The script you found uses the New-Object cmdlet to create an instance of the COM object named Schedule.Service. There are two main ways to find out more information about this object. The first is that you can list its properties and methods directly within PowerShell using the Get-Member cmdlet. This cmdlet works for both .NET and COM objects. It is an invaluable cmdlet that will show you what you can do with your objects. Use man or Get-Help Get-Member to learn about it. In fact you can use Get-Member to discover the object members you asked about such as the .connect method. The second way is to look up the documentation for the object on MSDN which is Microsoft's developer documentation website. This is probably the best page for that particular object.
I am not familiar with powershell scripting but found this, maybe some reference to use:
http://technet.microsoft.com/eng-us/scriptcenter/powershell%28en-us%29.aspx
http://technet.microsoft.com/en-us/library/hh857339.aspx#BKMK_wps4
On the first link are PowerShell Scripting Webcasts to find and more.
Scheduling Jobs with the Windows PowerShell API: http://msdn.microsoft.com/en-us/library/windows/desktop/jj150476%28v=vs.85%29.aspx
Guide to getting started with Windows PowerShell: http://technet.microsoft.com/library/ee221100.aspx
About Windows PowerShell, following help topics:
get-command : Gets information about cmdlets from the cmdlet code.
get-member : Gets the properties and methods of an object.
where-object : Filters object properties.
about_object : Explains the use of objects in Windows PowerShell.
about_remote : Tells how to run commands on remote computers.
Conceptual help files are named "about_", such as:
about_regular_expression.
The help commands also display the aliases of the cmdlets. These
are alternate names or nicknames that are often easier to type.
For example, the alias for the Invoke-Command cmdlet is "remote".
To get the aliases, type:
get-alias
Hopefully this will help a little.
The first hit on Google for "powershell create scheduled task" leads here, where one of the answers refers to the Schedule.Service COM object. That object's documentation gives you a list of all the methods and properties of the object.
You can also use get-member to discover all the methods & properties of any variable or object in your session.
$schedule = new-object -com Schedule.Service
TypeName: System.__ComObject#{2faba4c7-4da9-4013-9697-20cc3fd40f85}
Name MemberType Definition
---- ---------- ----------
Connect Method void Connect (Variant, Variant, Variant, Variant)
GetFolder Method ITaskFolder GetFolder (string)
GetRunningTasks Method IRunningTaskCollection GetRunningTasks (int)
NewTask Method ITaskDefinition NewTask (uint)
Connected Property bool Connected () {get}
ConnectedDomain Property string ConnectedDomain () {get}
ConnectedUser Property string ConnectedUser () {get}
HighestVersion Property uint HighestVersion () {get}
TargetServer Property string TargetServer () {get}
The Component Object Model is a core piece of Windows and there are hundreds if not thousands of COM objects available in default Windows installation for interacting with both the OS and other software installed (software can install its own set of objects as well). A lot of it can be replaced with .NET Framework assemblies and PowerShell modules, snap-ins and cmdlets now.
How do you discover COM objects? Usually via Google - running searches for the things you're trying to do, and typically you'll find someone has already posted something about similar, or your search will key off words in the object's own documentation online.
If you're using PowerShell 3, you don't need to use Schedule.Service at all - there's a set of cmdlets for working with scheduled tasks. See New-ScheduledTask for a starter.
If you're looking for a generic PowerShell tutorial, I usually point people at this one
You're on the right track in that Get-Command *foo* will list all Cmdlets containing the word foo, and Get-Help New-Object will show you the help file for the New-Object cmdlet.
However, you then go straight into using COM objects, which far predate Powershell. COM programming is old and can be quite archaic. Powershell lets you interface with COM, but it's not really the "Powershell way" of doing things.
In Powershell 3, I was able to find Register-ScheduledJob:
The Register-ScheduledJob cmdlet creates scheduled jobs on the local computer.
If possible I would say that is the preferred approach over using the COM interface, just because it's likely easier and more Powershelley.
I am a newbie when it comes to PowerShell and come from a BASH background from long ago. PowerShell's built-in documentation and help on the web is pretty good, but one area where I keep stumbling is understanding Methods and Properties (are these called members/classes?). I know that I can see which Methods and Properties I can use by doing, as in example:
ls | get-member
How do .Exists, .Trim, .SubString, or .Split, etc. actually work?
When you do Get-Member, you will see the TypeName, something like:
TypeName: System.IO.DirectoryInfo
You can search for that type and look at its members.
These are .NET framework objects and its members and properties, so you can make use of the extensive documentation at msdn.
For example this is the doc for DirectoryInfo: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx
I just posted a script to the scripting repository that may help you with this. http://gallery.technet.microsoft.com/scriptcenter/Finding-reference-b12324bc
It takes away the effort for you so now you can do something like:
Get-ChildItem C:\Windows | Get-Member | .\Find-TypeReference.ps1
Which would cause the script to open up the MSDN search page for you with the FileInfo and DirectoryInfo types as the query.