Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:22
    mklement0 commented #18343
  • 12:18
    mklement0 commented #18343
  • 09:55
    jhoneill commented #18373
  • 09:06
    jhoneill commented #18343
  • 04:01
    shaheerxt commented #6932
  • 03:51
    msftbot[bot] assigned #18400
  • 03:51
    pull-request-quantifier[bot] commented #18400
  • 03:51
    pull-request-quantifier[bot] labeled #18400
  • 03:51
    adityapatwardhan opened #18400
  • 03:10
    msftbot[bot] unlabeled #18154
  • 03:10
    iSazonov commented #18154
  • 03:01
    iSazonov labeled #18395
  • 02:51
    iSazonov unassigned #18398
  • 02:51
    iSazonov edited #18398
  • 02:49
    iSazonov commented #18398
  • 02:39
    iSazonov unlabeled #18399
  • 02:39
    iSazonov labeled #18399
  • 01:15
    xtqqczze edited #18399
  • 01:14
    xtqqczze labeled #18399
  • 01:14
    xtqqczze opened #18399
Will Pittenger
@will_pittenger:matrix.org
[m]
I've been going through Create a Crescendo cmdlet - PowerShell | Microsoft Docs. Unfortunately, there's a problem with the samples is that a parameter might be optional in one parameter set, but mandatory in another.
Will Pittenger
@will_pittenger:matrix.org
[m]
In my case, I'm working on a cmdlet where several parameters can be specified, but you must specify at least one.
No mention is made of the Position option for the ParameterAttribute.
Will Pittenger
@will_pittenger:matrix.org
[m]
Well, I created PowerShell/Crescendo#132.
Will Pittenger
@will_pittenger:matrix.org
[m]
Also, can a parameter be one of several types? For instance, if the parameter is a URL, I like to accept either a System.URI or a string. For a folder, I like to take either a System.IO.Directory or a string.
4 replies
HRXN
@Hrxn
Are the PowerShell community extensions (Pscx) still actively developed? Does anyone know?
JamesLear92
@JamesLear92
Hi guys, I raised a feature request issue ~2 years ago, and the thread is pretty dead. I've just realised that the issue doesn't have a "Needs Triage" label, and I can't see any way to add the label myself.
Is there anyone here who can add labels to issues?
PowerShell/PowerShell#12047
Will Pittenger
@will_pittenger:matrix.org
[m]
Weird. On Windows 11 Pro, PowerShell 7.2.4 thinks it's running on Windows 10.0.22000.
Will Pittenger
@will_pittenger:matrix.org
[m]
So '' would be invalid as would c:\.
If I'm expecting a System.Guid, I don't want them passing 4. Plus, this way, I'm not converting objects to/and from string as much.
Will Pittenger
@will_pittenger:matrix.org
[m]
Crescendo needs a documentation site for the schema. It should provide details on each field and samples. For instance, a page should be present describing the HandlerType and Handler members of a OutputHandler member. What do those values mean? A few random blog posts don't count. It would appear that HandlerType can only have one of several values. So list them and describe each. Then describe how that affects how Handler is interpreted.
1 reply
Will Pittenger
@will_pittenger:matrix.org
[m]
Can a PowerShell class declare events?
Doesn't look like it.
will_pittenger
@will_pittenger:matrix.org
[m]
If I have a string with an unknown number of whitespace characters at the start, is there a handy way to determine how many?
will_pittenger
@will_pittenger:matrix.org
[m]
Well, I wrote a class method:
    hidden [int]GetIndentLevel()
    {
        $this.CurLine -match '^(?<Indent>\s*';
        return $Matches.Indent -split '(  |\t)';
    }
Will Pittenger
@will_pittenger:matrix.org
[m]
Are PowerShell classes passed by reference? I'm looking for the equivilent of the C# ref keyword so I can have a function I call make changes to a variable in my scope.
I see [ref], but that's a type by itself and ruins my type safety. I'd rather declare the parameter as ref [int] name and pass the variable with ref valueVar like I would with C#.
The documentation for [ref] also seems to suggest it's mainly for COM.
People still explicitly use COM?
So 1990s.
Will Pittenger
@will_pittenger:matrix.org
[m]
Well, based on this, that's a resounding no.
C:\Users\willp> function Test([string]$x){$x = '%'}
C:\Users\willp> $g = 'dgfd'
C:\Users\willp> Test($g)
C:\Users\willp> $g
dgfd
C:\Users\willp> function Test([ref]$x){$x = '%'}
C:\Users\willp> Test($g)
Test: Cannot process argument transformation on parameter 'x'. Reference type is expected in argument.
Neither option worked.
Will Pittenger
@will_pittenger:matrix.org
[m]
Well, I had the usage of [ref] wrong, but I'm still missing something.
C:\Users\willp> Test(([ref]$g))
C:\Users\willp> $g
dgfd
C:\Users\willp> function Test([string]$x){$x = '%'}
C:\Users\willp> Test(([ref]$g))
C:\Users\willp> $g
dgfd
2 replies
Will Pittenger
@will_pittenger:matrix.org
[m]
I got it working, but I don't like the lack of type safety. I don't know why my C# PowerShell module won't load, but if I can figure it out, I'm scrapping this script and starting over in C#.
Probably would result in faster code.
Will Pittenger
@will_pittenger:matrix.org
[m]
Does PowerShell have problems with Module names that have periods, ., in them?
Jaykul
@jaykul:poshcode.org
[m]
Nope. The built in modules all do?
Will Pittenger
@will_pittenger:matrix.org
[m]
Also, does anyone have ideas on how to do a true native xcopy/xmove for PowerShell? copy -recurse tends to flatten the structure.
HRXN
@Hrxn
What do you mean, "flatten the structure"? Copy-Item -Recurse should copy everything as is? Never noticed anything different here, to be honest.
Mochtar van de Griendt
@Aprazeth
Unless you're using the incorrect/no quotes when providing source and/or destination, Copy-Item -Recurse should indeed keep everything as-is in terms of the structure (assuming permissions are also correct and such)
Jaykul
@jaykul:poshcode.org
[m]
Wrong tab
Will Fuqua
@waf

Hi, anyone have any insight into why Invoke-RestMethod is behaving differently on my local PC vs on GitHub Actions?

$nugetServer = "https://api.nuget.org/v3-flatcontainer/PrettyPrompt/index.json"
$publishedversions = (Invoke-RestMethod -Method Get -Uri $nugetServer -Verbose).versions

On my local machine, that call works (HTTP 200); but on GitHub Actions, nuget.org returns an HTTP 404. Is there some sort of environment difference that Invoke-RestMethod uses beyond what I specify at the command line? The only thing I can find is that Invoke-RestMethod respects proxy configuration via environment variables, but I don't think proxies are configured in GitHub Actions.

The failing job with more output is here: https://github.com/waf/PrettyPrompt/runs/7305443603?check_suite_focus=true

3 replies
Will Pittenger
@will_pittenger:matrix.org
[m]
Does PS 7 come with Powershell wrappers for dotnet.exe?
HRXN
@Hrxn
Not sure, but I think you can add argument completion for the dotnet tool to your $PROFILE:
## Add argument completer for the dotnet CLI tool
$scriptblock = {
    param($wordToComplete, $commandAst, $cursorPosition)
    dotnet complete --position $cursorPosition $commandAst.ToString() |
        ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock $scriptblock
Have not tried this for myself yet though, caveat emptor
jkjk ing
@jkjk_ing_gitlab
image.png
Hello folks,
I'm new here, and am looking to make my first contribution to the repo.
I'm having trouble building master at the moment, and was wondering if anyone might be able to point me in the right direction here.
TIA.
Will Pittenger
@will_pittenger:matrix.org
[m]
Is there a PowerShell equivalent to ipconfig /renew?
Jaykul
@jaykul:poshcode.org
[m]
Yeah, Ipconfig -renew
1 reply
Will Pittenger
@will_pittenger:matrix.org
[m]
Also, it'd help if the ArgumentCompletions attribute could take a collection of strings rather than requiring a comma delimited list.
In my case, I have a collection generated at runtime. Using [ArgumentCompleter] instead looks like a pain. Something like [ArgumentCompletions($array)] makes more sense.
Will Pittenger
@will_pittenger:matrix.org
[m]
When I create a class with the member shown below, Visual Studio Code promptly breaks it trying to wrap the code to fit on one line.
    hidden $mapCommonTimeZones =
    @{
        'UTC' = [TimeZoneInfo]::UTC;
        'PST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Pacific Standard Time') | Where-Object { $_.DisplayName -match '\(US \& Canada\)'})[0];
        'MST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Mountain Standard Time'))[0];
        'CST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Central Standard Time') | Where-Object { $_.DisplayName -match '\(US \& Canada\)'})[0];
        'EST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Mountain Standard Time'))[0];
    };
It transforms that into:
    hidden $mapCommonTimeZones =
    @{
        'UTC' = [TimeZoneInfo]::UTC;
        'PST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Pacific Standard Time') | Where-Object
            { $_.DisplayName -match '\(US \& Canada\)'
            })[0];
        'MST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Mountain Standard Time'))[0];
        'CST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Central Standard Time') | Where-Object
            { $_.DisplayName -match '\(US \& Canada\)'
            })[0];
        'EST' = ([TimeZoneInfo]::FindSystemTimeZoneById('Mountain Standard Time'))[0];
    };
Seems the line breaks it adds between where-object and the script block for that where-object are illegal.
It doesn't do that for a constant outside a class.
Flavio Campana
@SilverXXX
Hello everyone, is there any way to change $PROFILE location? I have a work laptop with windows 10 with onedrive and it can't execute profile script correctly
Will Pittenger
@will_pittenger:matrix.org
[m]
Instead, it just links to a general .NET discussion that assumes you're working directly with those types.
lub
@lub:imninja.net
[m]
Will Pittenger you can use the general .NET options directly in -match https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference#miscellaneous-constructs
it's the .NET regex engine after all, so everything that's documented there should also apply to powershell
> 'asef
>> bsef
>> csef' -match 'asef$'
False
> 'asef
>> bsef
>> csef' -match '(?m)asef$'
True
>