{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2834","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2834/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2834/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2834/events","html_url":"https://github.com/PowerShell/PowerShell/issues/2834","id":193179241,"number":2834,"title":"Allow both the mandatory attribute to be set along with a default value and only force input if the default value is $null","user":{"login":"DarqueWarrior","id":3853405,"avatar_url":"https://avatars.githubusercontent.com/u/3853405?v=3","gravatar_id":"","url":"https://api.github.com/users/DarqueWarrior","html_url":"https://github.com/DarqueWarrior","followers_url":"https://api.github.com/users/DarqueWarrior/followers","following_url":"https://api.github.com/users/DarqueWarrior/following{/other_user}","gists_url":"https://api.github.com/users/DarqueWarrior/gists{/gist_id}","starred_url":"https://api.github.com/users/DarqueWarrior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DarqueWarrior/subscriptions","organizations_url":"https://api.github.com/users/DarqueWarrior/orgs","repos_url":"https://api.github.com/users/DarqueWarrior/repos","events_url":"https://api.github.com/users/DarqueWarrior/events{/privacy}","received_events_url":"https://api.github.com/users/DarqueWarrior/received_events","type":"User","site_admin":false},"labels":[{"id":401720878,"url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Area-Language","name":"Area-Language","color":"5319e7","default":false},{"id":423526741,"url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Issue-Discussion","name":"Issue-Discussion","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-02T17:59:54Z","updated_at":"2016-12-09T06:04:11Z","closed_at":null,"body":"When defining a function, I would like to use an environment variable as the default value. If the environment variable exists and has a value that value will be used. For example,\r\n\r\nfunction Get-Info ([Alias(\"name\")] [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [string] $projectName = **$env:Project_Name**) \r\n{ \r\n}\r\n\r\nInstead of having to passing in the Project Name for each call I would like to store it in an environment variable. When I do it would allow me to call Get-Info with no parameters and the value in the environment variable would be used. If the environment variable does not exist or is empty the user would be prompted for a value if it was not provided on the command line. \r\n\r\nI tried writing the code as I have above but it never seemed to work. Even when the environment variable was set I was always prompted for projectName. \r\n\r\nI know I could remove the mandatory attribute and add code in my function to set to the environment variable if it exists. But it would be much easier if what I am proposing was possible. \r\n\r\nI also thought about using $PSDefaultParameterValues. This would almost be a short hand version of that set by the function writer and not the user."},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/265940847","html_url":"https://github.com/PowerShell/PowerShell/issues/2834#issuecomment-265940847","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2834","id":265940847,"user":{"login":"DarqueWarrior","id":3853405,"avatar_url":"https://avatars.githubusercontent.com/u/3853405?v=3","gravatar_id":"","url":"https://api.github.com/users/DarqueWarrior","html_url":"https://github.com/DarqueWarrior","followers_url":"https://api.github.com/users/DarqueWarrior/followers","following_url":"https://api.github.com/users/DarqueWarrior/following{/other_user}","gists_url":"https://api.github.com/users/DarqueWarrior/gists{/gist_id}","starred_url":"https://api.github.com/users/DarqueWarrior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DarqueWarrior/subscriptions","organizations_url":"https://api.github.com/users/DarqueWarrior/orgs","repos_url":"https://api.github.com/users/DarqueWarrior/repos","events_url":"https://api.github.com/users/DarqueWarrior/events{/privacy}","received_events_url":"https://api.github.com/users/DarqueWarrior/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T06:04:11Z","updated_at":"2016-12-09T06:04:11Z","body":"The only difference in my use case was the setting of $PSDefaultParameterValues was in a different function than where it was used. Second I use add not = so I did not overwrite existing entries. I had a convenience function that added entries to $PSDefaultParameterValues but when I then called a function the values were not in $PSDefaultParameterValue. It was as if they were only scoped and existed where they were set not outside. I will have time today to try again. "}}
{"actor":{"display_login":"DarqueWarrior"}}