Just_RC
asked on
PSCredential (function) in PS profile
Experts:
Good evening. If I could get this to work it'd sure be helpful. We have a platform exposed to a power-shell module to which we have to authenticate to. I put the following function in my power-shell profile:
function Set-DefaultCreds {
$passwd = ConvertTo-SecureString "mypasswd" -AsPlainText -Force
$creds = New-Object System.Management.Automati on.PSCrede ntial ("admin", $passwd)
}
Now...when I launch into a powershell session, I can type Set-Default [tab] and it auto-completes, however I get no value from "$creds"
Any thoughts would be greatly appreciated.
Have a great week.
Good evening. If I could get this to work it'd sure be helpful. We have a platform exposed to a power-shell module to which we have to authenticate to. I put the following function in my power-shell profile:
function Set-DefaultCreds {
$passwd = ConvertTo-SecureString "mypasswd" -AsPlainText -Force
$creds = New-Object System.Management.Automati
}
Now...when I launch into a powershell session, I can type Set-Default [tab] and it auto-completes, however I get no value from "$creds"
Any thoughts would be greatly appreciated.
Have a great week.
ASKER
Sorry..swamped at work. No joy. The object isn't there on-boot, but I can call it as before....
From my profile:
function Set-DefaultCreds
{
$passwd = ConvertTo-SecureString "admin12345!" -AsPlainText -Force
$creds = New-Object System.Management.Automati on.PSCrede ntial ("admin", $passwd)
}
Set-DefaultCreds
Then from my session:
PS D:\> $creds
PS D:\> Set-DefaultFreds
PS D:\> $creds
PS D:\>
..but I set them through the GUI....
PS D:\> $creds
PS D:\> get-credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
UserName Password
-------- --------
\admin System.Security.SecureStri ng
From my profile:
function Set-DefaultCreds
{
$passwd = ConvertTo-SecureString "admin12345!" -AsPlainText -Force
$creds = New-Object System.Management.Automati
}
Set-DefaultCreds
Then from my session:
PS D:\> $creds
PS D:\> Set-DefaultFreds
PS D:\> $creds
PS D:\>
..but I set them through the GUI....
PS D:\> $creds
PS D:\> get-credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
UserName Password
-------- --------
\admin System.Security.SecureStri
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks...
I will add that line, but I'm almost sure I tried that before.
Will advise...and thank you again for your help.
I will add that line, but I'm almost sure I tried that before.
Will advise...and thank you again for your help.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for Just_RC's comment #a38389076
for the following reason:
return $creds within function did the trick. Thank you.
Accepted answer: 0 points for Just_RC's comment #a38389076
for the following reason:
return $creds within function did the trick. Thank you.
I'm confused was the answer provided or not?
Open in new window
OrOpen in new window
Personally I would return the creds variable.$creds = Set-DefaultCreds