Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Moving New-Guid to compiled cmdlet#2752

Merged
lzybkr merged 1 commit into
PowerShell:masterPowerShell/PowerShell:masterfrom
powercode:new-guid-cmdletpowercode/PowerShell:new-guid-cmdletCopy head branch name to clipboard
Dec 1, 2016
Merged

Moving New-Guid to compiled cmdlet#2752
lzybkr merged 1 commit into
PowerShell:masterPowerShell/PowerShell:masterfrom
powercode:new-guid-cmdletpowercode/PowerShell:new-guid-cmdletCopy head branch name to clipboard

Conversation

@powercode

@powercode powercode commented Nov 21, 2016

Copy link
Copy Markdown
Collaborator

Fixing #2733
Simplest implementation possible

@msftclas

Copy link
Copy Markdown

Hi @powercode, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty should be all zeros. Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We indent with spaces, not tabs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I wish that tab/spaces was a per project setting in VS...
DICE has tabs, and switching back and forth is a mess...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cmdlet suggests that it creates a new object every time it's called, but with this parameter, nothing is actually created.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you have noting before, and after you have a guid. Admittedly a static one that will never change, but it is friendlier to type new-guid -e than [guid]::empty, especially with Scandinavian keyboards, where '[' is on AltGr+8.

But it's your call. Remove?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code feels like it doesn't belong in a cmdlet with the verb New, and I don't think we want a cmdlet Convert-ToGuid.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Copy from Issue) Some applications use GUID as a unique identifier. In this case, the identifier is a string. So really, we can get a stream of strings (ex. from logs), that we want to convert to [guid] . And yes this is more for ConvertTo-Guid but I looked through New-* cmdlets and many of them do a similar operation (string -> object). Most likely the new ConvertTo-Guid cmdlet is redundant and perhaps it would be better to make the GUID parameter.

@powercode powercode force-pushed the new-guid-cmdlet branch 2 times, most recently from 5368d9b to 73e2706 Compare November 21, 2016 21:46

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to update map.json for new files.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this parameter is redundant.
The only cmdlet that uses Count parameter is Get-Random and only to determines how many objects are returned from input pipeline.
Usually we do so:

0..9 | New-Guid

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to me, that looks like the input in some way should be related to the created guids.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the sample is incorrect.
I mean:

0..10 | % { Get-Random }

@iSazonov iSazonov Nov 22, 2016

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely you had in mind:
if (String.Equals(ParameterSetName, "Empty", StringComparison.OrdinalIgnoreCase))
or
if (ParameterSetName == "Empty")

@powercode powercode Nov 22, 2016

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the empty switch will only be on if the parameterset is "Empty" so it seems like a cheaper and simpler test. They are functionally equivalent, but I think this is easier to read

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using if (Empty) here will also handle a rare usage of the cmdlet: New-Guid -Empty:$false -- it will write out a new GUID in that case.

@PowerShellTeam PowerShellTeam added the Review - Needed The PR is being reviewed label Nov 22, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment probably should be Return one or more guids.

@daxian-dbw daxian-dbw removed the Review - Needed The PR is being reviewed label Nov 23, 2016
@lzybkr lzybkr added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Nov 24, 2016
@lzybkr lzybkr self-assigned this Nov 24, 2016
@lzybkr

lzybkr commented Nov 24, 2016

Copy link
Copy Markdown
Contributor

Don't merge yet - I've marked this for committee review.

I personally wouldn't mind removing this command, or if we do, it should work just like the existing function, nothing more, but we should decide that as a committee.

@iSazonov

Copy link
Copy Markdown
Collaborator

I analyzed using NewGuid by @daxian-dbw method
Found 133 *.ps1 scripts on GitHub (I did not search *.psm1).
Thus it is very rarely used cmdlet.

I manually inspected these scripts.
I did not find that this cmdlet was used in loops.
I did not find using Empty guids.

A common usage (in descending order of popularity):

$GUID = (New-Guid).Guid

[string]$Name = (New-Guid).ToString()

$id = New-Guid
$name = "Solution_$id"

$wpconfig = $wpconfig.Replace("eisauthkey",$(New-Guid))

function New-Guid {
    [System.Guid]::NewGuid().ToString("d").Substring(0, 4).Replace("-", "")
}

$guid = (New-Guid).GUID.Replace("-","_")

@PowerShellTeam PowerShellTeam added the Review - Needed The PR is being reviewed label Nov 24, 2016
/// <summary>
/// returns a guid
/// </summary>
protected override void EndProcessing()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EndProcessing [](start = 32, length = 13)

this implementation subtly changes the current implementation (the function uses Begin rather than End as is here) - I don't believe it to be a big problem, but thought I should add the note

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Dec 1, 2016
@SteveL-MSFT

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee we discussed this and for discovery reasons as well as shipping this previously, we should have new-guid even though it's a simple operation for users familiar with the guid class

@lzybkr lzybkr merged commit 5484b98 into PowerShell:master Dec 1, 2016
@powercode powercode deleted the new-guid-cmdlet branch December 6, 2016 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Committee-Reviewed PS-Committee has reviewed this and made a decision Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.