3 ms·
Things I like about PowerShell include objects - cmdlets return them and you can call methods. For example, you can get a list of services (get-service) and eac
by thoth 11y ago
Things I like about PowerShell include objects - cmdlets return them and you can call methods. For example, you can get a list of services (get-service) and each is a ServiceController object, which you can Start(), Stop(), etc.
Things I don't like, or is a pain point for me, are those same objects. As far as I can tell, there isn't a better way to figure out what you actually are getting back from a cmdlet besides feeding output through Get-Member.
For example, what comes back from dir/ls/Get-ChildItem? Well that's a trick question because it depends on which "provider" you invoke. On a file system (dir somedirectory) you'll get back FileInfo or Directory info, for a registry hive (dir hklm:) you'll get a RegistryKey, for environment variables (dir env:) you get a DictionaryEntry, etc.
So while it is fantastic there is a general way to enumerate items, the docs have to be vague and list System.Object as what returns from Get-ChildItem and its various aliases, which isn't very useful for working with the results.
This makes forming non-trivial commands with pipelines fairly annoying because I have to feed each stage through Get-Member to even figure out what I have and what is now available; this strategy starts to break down if a pipeline stage feeds a loop, etc.
I'd love it if the ISE displayed what actual object type exists at every point of a pipeline, rather than the trial-and-error-by-Get-Member approach I've adopted. Or for there to be some better way to get the return type of a cmdlet.
PowerShell is a huge improvement over the old command prompt though.
- 13of40 11y ago> what comes back from dir/ls/Get-ChildItem? If you look at the note properties that get added to the objects, they're consistent across providers: PS C:\> (Get-Item c:\).PSPath Microsoft.PowerShell.Core\FileSystem::C:\ PS C:\> (Get-Item env:username).PSPath Microsoft.PowerShell.Core\Environment::username PS C:\> (Get-Item HKLM:\software).PSPath Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software There's also some magic that you can do with tab completion to see the properties. For example, if you type... (Get-ChildItem c:\ | sort). ...and hit tab, you can tab through the list of properties of the objects returned by Get-ChildItem when it's used on the FileSystem provider. (Don't ask me how the hell that works, though...)