For generic PowerShell questions you can use the community slack http://slack.poshcode.org/
ParameterAttribute.
System.URI or a string. For a folder, I like to take either a System.IO.Directory or a string.
System.Guid, I don't want them passing 4. Plus, this way, I'm not converting objects to/and from string as much.
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.
hidden [int]GetIndentLevel()
{
$this.CurLine -match '^(?<Indent>\s*';
return $Matches.Indent -split '( |\t)';
}
ref keyword so I can have a function I call make changes to a variable in my scope.
[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#.
[ref] also seems to suggest it's mainly for COM.
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.
[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
., in them?
copy -recurse tends to flatten the structure.
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).versionsOn 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
dotnet.exe?
$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
ArgumentCompletions attribute could take a collection of strings rather than requiring a comma delimited list.
[ArgumentCompleter] instead looks like a pain. Something like [ArgumentCompletions($array)] makes more sense.
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];
};
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];
};
where-object and the script block for that where-object are illegal.
-match, how do you tell it you want a Multi-Line match? https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7.2#anchors doesn't describe that.
> 'asef
>> bsef
>> csef' -match 'asef$'
False
> 'asef
>> bsef
>> csef' -match '(?m)asef$'
True
>