Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 20:19
    daxian-dbw labeled #15039
  • 20:19
    daxian-dbw unlabeled #15039
  • 20:03
    daxian-dbw labeled #16438
  • 19:54
    pull-request-quantifier[bot] commented #16490
  • 19:54
    pull-request-quantifier[bot] commented #16490
  • 19:54
    daxian-dbw synchronize #16490
  • 19:42
    unfurl-links[bot] commented #16694
  • 19:42
    daxian-dbw commented #16694
  • 19:23
    jborean93 commented #16763
  • 19:00
    msftbot[bot] labeled #16734
  • 18:58
    iSazonov labeled #16766
  • 18:54
    iSazonov commented #16767
  • 18:52
    jborean93 commented #16766
  • 18:51
    iSazonov labeled #16767
  • 18:51
    iSazonov labeled #16767
  • 18:40
    adityapatwardhan edited #16768
  • 18:40
    adityapatwardhan edited #16768
  • 18:40
    adityapatwardhan edited #16768
  • 18:40
    adityapatwardhan edited #16768
  • 18:40
    adityapatwardhan edited #16768
tejaswivg
@tejaswivg
another question: why can't I ping a computer on the same network. I can see its ip address when I type in "arp -a"
Mochtar van de Griendt
@Aprazeth
@tejaswivg That goes beyond the scope of PowerShell itself? I'd suggest checking the firewall, and which zone the network is placed in (Private, Work, Public) as that might also be a thing. If that doesn't work, try Google or your search-engine of choice :)
Wolfgang Groß
@wgross

I have question for the scripting pros :-)

Is there a way to propagate $Verbose and $Debug automatically to a function imported from a different module?

I know there is no such thing like 'Import-Module -Scope Current' but maybe some has some tricks how to achieve this like fiddling with the session state or something like that or has written a cool cmdlet to achieve this?
This is own of the most annoying problem I have with PS and the organization of me modules. I've searched the interweb already and have'nt found much except some people walking the stack trace upwards.

Also i've also read $debug should be propagated which i can't reproduce with PS 7.1 at least.

Joel Sallow (/u/ta11ow)
@vexx32
Automatically? No. I guess I'd call it sort of a bug in powershell itself that those automatic parameter values don't propagate their values across module boundaries
they're propagated to any compiled commands, but any script commands from a different module won't inherit them automatically
Wolfgang Groß
@wgross

@vexx32 Yes... i'm sure that there are (technical) reasons for this kind of isolation of modules but it is completely opposite to my expectations :-)

I't fiddling around with code like this:

function _inherit_verbose_preference {
    $verbose = (Get-PSCallStack | Where-Object { $null -ne $_.InvocationInfo.BoundParameters.Verbose } | Select-Object -First 1).InvocationInfo.BoundParameters.Verbose
    if($verbose) {
        Set-Variable -Name "VerbosePreference" -Scope 1 -Value "Continue"
    }
}

but have not achieved a satisfying 'modus operandi' with this ... It only works in some situations

Will Pittenger
@will_pittenger:matrix.org
[m]
I have a PowerShell script attempting to validate a value. The parameter's type is object. The value must be either a string that can be typecast to regex or a regex value. So I have [ValidateScript({$regexMatchTitle -is [string] -and ([regex]$regexMatchTitle -ne $null) -or $regexMatchTitle -is [regex]})]. This works when I test it outside the function, but not for real. When I try to call the function with $regexMatchTitle set to either '^race' or [regex]'^race', I get an error that the validation script returned a value other than True.
What am I doing wrong?
Wolfgang Groß
@wgross
@will_pittenger:matrix.org is $regexMatchTitle the name of the parameter? Usually I refer to the value to check in a ValidateScript with the variable name '$_' and not with the cmdlet parameter name.
Will Pittenger
@will_pittenger:matrix.org
[m]
It is. I thought that was the correct way to refer to the parameter. I didn't know $_ would work there.
Wolfgang Groß
@wgross
Its like the parameter value "is piped in" the validation script.
Will Pittenger
@will_pittenger:matrix.org
[m]
OK.
Will Pittenger
@will_pittenger:matrix.org
[m]
@wgross: So what do I do if $_ is a maximum and I want to make sure that the corresponding minimum parameter, if specified, is less?
Do I retrieve the minimum value from $PSBoundParameters?
Wolfgang Groß
@wgross
So this is a specified parameter? I wuld not expect that two parameters can be verified in the ValidateScript attribute.
If two parameter must be validated together i would do this in the script code. most likely in the "begin {}" section of the function if their values aren't read from the pipe.
Mochtar van de Griendt
@Aprazeth
Would something like ValidateRange not perhaps be an option? Also, it might perhaps be an idea to rethink your input parameters; instead of having "-Minimum" and "-Maximum" (for example) it might make more sense to do a "-Range" parameter
Will Pittenger
@will_pittenger:matrix.org
[m]
@Aprazeth: And if they only want one end of that range?
Mochtar van de Griendt
@Aprazeth
@will_pittenger:matrix.org There are ways to detect that, for example if input is 1 number instead of say 2 or such - do not check the range. The other option is to use a parameterset; one for the range, the other for a singular end
Mochtar van de Griendt
@Aprazeth
Also, you could do a required parameter such as "-Begin" (required) and another parameter that says "-Range 100" (not required). If range is not provided you just go for the one, if range is provided you can have the script go from the value in parameter Begin and go from there.
(bit sleep deprived here so apologies for any typos and such :) )
Will Pittenger
@will_pittenger:matrix.org
[m]
@Aprazeth: I'm wrapping a perl app. It's their parameters mine correspond to.
Mochtar van de Griendt
@Aprazeth
@will_pittenger:matrix.org Do you have any control over the data itself being sent to the PowerShell script? Just like in PowerShell, it applies to all systems - best to clean up before sending it over. If not, best to indeed build in validation and take it from there (well, always build in validation :) )
Will Pittenger
@will_pittenger:matrix.org
[m]
Well, it's for my own personal use.
Mochtar van de Griendt
@Aprazeth
If possible see what you can cleanup in the perl program in terms of the output (regardless of whether you then use powershell or something else after that, it's best practice to make sure data being sent out is formatted correctly) That said - I think with some of the options mentioned here you could also have the powershell script sort things out on its own :)
Mochtar van de Griendt
@Aprazeth
Wait @will_pittenger:matrix.org is it a numerical range you are getting back? If so, you might be able to do something like this using Sort-Object
$NormalRange = 1..10
$Id10tRange = 10..1

$Id10tRange | Sort-Object
Write-Output -InputObject 'Now for something completely different'
$NormalRange | Sort-Object
The output you should see is always going from 1 to 10 - even if the variable was filled in reverse (because sort-object sorts ascending by default)
Will Pittenger
@will_pittenger:matrix.org
[m]
I'd actually to specify ..5 or 5.., but those are syntax errors.
Will Pittenger
@will_pittenger:matrix.org
[m]
Unfortunately, range isn't a type, but a syntax for listing a contiguous sequence.
Mochtar van de Griendt
@Aprazeth
So if I understand you correctly, the perl program spits out the data in format "...[number]" or "[number...]", or possible "[number]" ? Also, feel free to DM me directly here (just in case anyone gets a bit miffed at our constant chatting ;) )
Will Pittenger
@will_pittenger:matrix.org
[m]
No. I'm calling them. They have parameters like --playlist-start and --playlist-end.
Will Pittenger
@will_pittenger:matrix.org
[m]

@Aprazeth: They do have a --playlist-items. It's described as shown below:

Playlist video items to download. Specify indices of the videos in the playlist separated by commas like: --playlist-items 1,2,5,8 if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: --playlist-items 1-3,7,10-13, it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13.

However, I'm not using that option as of now.
Mochtar van de Griendt
@Aprazeth
@will_pittenger:matrix.org what, I think I have been mistaken this whole time. Are you using the powershell script to call the perl program or the other way around?
Will Pittenger
@will_pittenger:matrix.org
[m]
I call them.
When my script is called, I translate each parameter into the perl program's counterpart.
But since a start should always be less than a end, I'm trying to ensure that if both are specified, the start is less than the end.
Will Pittenger
@will_pittenger:matrix.org
[m]
@Aprazeth: ??? You still here?
Mochtar van de Griendt
@Aprazeth
Yeah I am. Anyway, I'd go with the option that @wgross suggested earlier. Probably the easiest to implement and get working
Had a few things to do here - hence
Will Pittenger
@will_pittenger:matrix.org
[m]
I'm writing a PowerShell module with C#. How do I detect that an optional parameter wasn't specified. Can I access $PSBoundParameters? Do I put ? on the parameter type? In this case, the optional parameter is an enum.
Mochtar van de Griendt
@Aprazeth
@will_pittenger:matrix.org Is that optional paremeter required by any chance in specific scenario? Say for example that an user uses paramater -From which then would require paramter -To to also be specified. If that's the case, you can perhaps use Parametersets
Mochtar van de Griendt
@Aprazeth
Also, there is a community discord for PowerShell at https://aka.ms/psdiscord - which might be a lot more active
Will Pittenger
@will_pittenger:matrix.org
[m]
@Aprazeth: I needed to derive from PSCmdLet rather than CmdLet. That provides access to the MyInvocations member which has BoundParameters.
Couleur
@couleurm
hi, just testing the bridge
wait why isn't it in #bridge on Discord
Sanam
@sanamhub
I've automated many tasks using PowerShell which were on my head.. Is there any resource where there is the list of "Tasks to automate via PowerShell"?
1 reply
zw5
@zw5
a