hi luc,
many a times we are defining $username and $password in param block as mandatory parametrs.
can yu suggest how get-credential can be defined in a similar way.
You have a comma after $Credential
{
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string]$cisserver,
[PSCredential]$Credential
)
}
Test-Credential -Credential (Get-Credential)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean like this?
PS: this also shows the weakness of a PSCredential password.
param(
[PSCredential]$Credential
)
$Credential.GetNetworkCredential() | Select *
}
Test-Credential -Credential (Get-Credential -Message 'Test credentials')
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
do i need to create a second param block .or how to put in an existing param block as follows???
function test-credential
{
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string]$cisserver,
[PSCredential]$Credential,
$Credential.GetNetworkCredential() | Select *
)
Connect-CisServer -server $cisserver -Credential $credential
}
That is the correct way, all in one param block,
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
but its giving me syntax error.
You have a comma after $Credential
{
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string]$cisserver,
[PSCredential]$Credential
)
}
Test-Credential -Credential (Get-Credential)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
below works .however i was expecting comma in orange line but it works .
i somehow rememer that we need to define parameter mandatory once in entire param block is this not the case??
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string]$cisserver,
[parameter(mandatory = $true)]
[PSCredential]$Credential
)
No, you need to define that per parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thnaks luc.