How to find new cmdlets in Powershell v3.0 - powershell

I wanted to find the new cmdlets / functions in Powershell. I used the following approach, but not sure if it is comprehensive / correct. Any ideas to find this in a better / different way?
Run the below once from v2 and once from v3 ( and write to a different file)
get-command -Module Microsoft.PowerShell.* |
select -expand name | out-file e:\poshv2.txt
Then use Compare-Object to see what's added ( or removed)
Compare-Object (gc e:\poshv2.txt) (gc e:\poshv3.txt)
My observation based on this is that there were 25 new cmdlets added ( and none were removed)
One question that was raised as a comment on my blog was that Disable-PsRemoting, which appeared in this list, is not really new. The reason it appeared was that it was not in the modules under Microsoft.Powershell.* ( and it was not a cmdlet), but it is in v3.0.

The only difference which you already noted is that in v2 Disable-PsRemoting was a function and in v3 it's a cmdlet. I wrote about cmdlet and parameter changes in v3 (using a similar compare method) on the PowerShell Magazine website.
http://www.powershellmagazine.com/2011/09/15/how-to-find-out-whats-new-in-powershell-vnext/

Related

How to view categories in Powershell v5?

im running powershell v5 on my machine and i can't seem to run the command
GET-HELP -Category Provider.
Is there an alternative to this command which can be used in v5 or is it a command that's available to v3 Powershell?
While Provider is a valid category for help topics, none of the topics that ship with PowerShell use category Provider (anymore), as of Windows PowerShell 5.1 / PowerShell (Core) 7.2.x
See GitHub issue #8030
The next best thing is to use a wildcard-based search, using the Get-Help's (positionally implied) -Name parameter:
Get-Help *provider*
This will list all topics with the word provider in the name, which comprises both cmdlets with the word in the name and conceptual help topics (topics whose name starts with about_).
If you want to limit the output to matching conceptual help topics (as Get-Help -Category Provider may have done in Windows PowerShell versions prior to v5.1):
Get-Help *provider* -Category HelpFile
# Alternative:
Get-Help about_*provider*
[1] The valid categories are: Alias, All, Class, Cmdlet, Configuration, DefaultHelp, DscResource, ExternalScript, FAQ, Filter, Function, General, Glossary, HelpFile, Provider, ScriptCommand, which correspond to the values of a non-public enumeration type, System.Management.Automation.HelpCategory; you can obtain these values programmatically with (TabExpansion2 'Get-Help -Category ' -cursorColumn 19).CompletionMatches.CompletionText.
The topics that ship with Windows PowerShell v5.1 / as of PowerShell (Core) 7.2.x span the following categories: Alias, Cmdlet, ExternalScript, Filter, Function, HelpFile, as obtained with (Get-Help *).Category | % ToString | Sort-Object -Unique
Using Windows Powershell 5.1. when I look at help Get-Help -full, I read the following:
Parameters
-Category <System.String[]>
Displays help only for items in the specified category and their aliases. Conceptual articles are in the HelpFile category.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
If I do a Get-Help * | Group-Object Category | Select-Object Name, I only see the following categories:
Alias
Function
ExternalScript
Cmdlet
HelpFile
I get the same categories in PowerShell v7.2

SpecialFolders with multiple versions of PowerShell

Is there a means in PS2.0 of getting at some of the Special Folders that are not enumerated until later versions?
For example, [Environment]::GetFolderPath("ProgramFilesX86") works in PS5.0 but produces an enumeration error in PS2.0. I was thinking maybe there is a .NET based approach, but my Google fu has me thinking that even in .NET prior to Framework 4 there is no way, but that also seems like a pretty glaring oversight.
The first of the below commands returns 47 in PowerShell 5.1.1 on Windows 10 1803. In PowerShell 2.0 on the same system, it returns 23. If you removed the pipe to Measure-Object and the Count property dotted notation, it'll actually show the names of the folders you can use. That's the seconds of the the below commands.
([enum]::GetNames([System.Environment+SpecialFolder]) | Measure-Object).Count
([enum]::GetNames([System.Environment+SpecialFolder]) | Sort-Object) -join "`n"
PowerShell 2.0 Special Folders:
ApplicationData
CommonApplicationData
CommonProgramFiles
Cookies
Desktop
DesktopDirectory
Favorites
History
InternetCache
LocalApplicationData
MyComputer
MyDocuments
MyMusic
MyPictures
Personal
ProgramFiles
Programs
Recent
SendTo
StartMenu
Startup
System
Templates

Get Registry Name using powershell

I wanted to loop through registry entries using powershell and uninstall certain MSIs.
I found the answer in this post very simillar to my requirement. However I have a slight different requirement. (I dont want to use UnInstall String)
I get a list of all registries in 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' and I want to use the NAME (i.e. the productcode) of the registry itself.
My Question: How to get the name of the registry.
You need to use Get-ChildItem.
For example, this gives the Name of the key under Uninstall key.
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | Select PSChildName
Update based on the comment:
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | Where-Object {
$_.PSChildName -Eq '{D2B9C003-A3CD-44A0-9DE5-52FE986C03E5}'} | Select PSChildName
You shouldn't really be trolling the registry. The correct way to do this for MSI-based installs is to use MsiEnumProducts to find all the installed MSI products, use the returned product code to get info about their names and versions (MsiGetProductInfo) to see if you want to uninstall them, and then use MsiConfigureProduct and set them to installstate_absent. If you dig around you may find some p/invoke interop code to do this from managed code, that would get you into PowerShell.

Create-Fixture in Pester (Powershell BDD) isn't working

I'm following the instructions from here:
http://scottmuc.com/blog/development/pester-bdd-for-the-system-administrator/
I'm finding that having installed and imported the module I still can't run Create-Fixture.
Has anyone come across this?
Turns out Create-Fixture isn't a cmdlet any more. I had a look here:
https://github.com/mwrock/Chocolatey-Packages/blob/master/pester/Pester.psm1
and realised the name of the cmdlet has been changed. It's now called New-Fixture.
If you run New-Fixture it even references Create-Fixture:
PS D:\edsource\Powershell> New-Fixture
invalid usage, please specify (path, name)
eg: .\Create-Fixture -Path Foo -Name Bar
creates .\Foo\Bar.ps1 and .\Foo.Bar.Tests.ps1

How do I get a list of all tfs alert subscriptions via powershell (get .Net assembly via PowerShell?)

I'm trying to move my tools to powershell, can this be done in PowerShell? the bit I'm really interested in is:
IEventService es = tfs.GetService(typeof(IEventService)) as IEventService;
List<Subscription> ls = es.GetAllEventSubscriptions().ToList();
Edit: what I really want to do might be using a .NET assembly from powershell and this might then be a duplicate of Using .NET library from PowerShell
Here is a TFS API in PowerShell function that I found on a blog long ago that will get you started. I've posted it to a GitHub Gist. Basically you ensure you've loaded up the TFS assemblies into the AppDomain and then you can add any TFS Service Interfaces you want to the object and just operate on them just as you would in any c# application, etc.
https://gist.github.com/3288447
Once you have the TFS object returned from the method in the Gist above, you can operate on the loaded services like so:
#use work item service
$tfs = get-tfs $env:TFSSERVERURL -silent
$project = $tfs.wit.Projects | ?{ $_.Name -eq $projectName}
#todo - replace with text for query or file read -- this is deprecated
$query = $project.StoredQueries | ?{ $_.Name -eq 'Active Bugs' }
$queryText = $query.QueryText.Replace("#project","'$projectName'")
$results = $tfs.wit.Query($queryText)
#do something with the results...
In your request above you can just alter the get-tfs method to add your service interface to the set loaded and then operate on the .NET methods much like I do in the example above.