[quote quote=137579]How are you executing the command ? please post that particular line of code and read documentation from Get-Help New-PSSession -Online.
Using Get-Help we can see the -Credential parameter expects a PSCredential Object. It sounds like you are not providing that as an argument for -Credential, but rather a string with a user name?
[pre]
Get-Help New-PSSession -Parameter credential
[/pre]
-Credential <PSCredential>
Specifies a user account that has permission to perform this action. The default is the current user.
Type a user name, such as User01, Domain01\User01, or User@Domain.com, or enter a PSCredential object, such as one returned by the Get-Credential cmdlet.
When you type a user name, this cmdlet prompts you for a password.
Required? false
Position? named
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
You would want to use Get-Credential to build a PSCredential Object.
That function doesnt seem necessary at face value, however I also do not understand the full purpose of your script. A couple of things though, you shouldn’t save formatted objects into variables. Instead format the output when its called, what I am not understanding is the function appears to retrieve info about your computer and the current logged on user. The -Credential parameter defaults to the user running the PS session, it just seems redundant to me, however the below snippet should function to prompt for the password for the username returned from $adminuser
[quote quote=137595]That function doesnt seem necessary at face value, however I also do not understand the full purpose of your script. A couple of things though, you shouldn’t save formatted objects into variables. Instead format the output when its called, what I am not understanding is the function appears to retrieve info about your computer and the current logged on user. The -Credential parameter defaults to the user running the PS session, it just seems redundant to me, however the below snippet should function to prompt for the password for the username returned from $adminuser
[/quote]
This is exactly it! I did not realize | ft user was including other info not just the value of the attribute.
I’m running that function (get-pswho) to get the domain\user of the person running the script. I googled for that and did not see anything like get-credential. I could have included a prompt for the username but the intention is to only run this as Admin so I thought it’d save a itty bit of time for the user.
“This is exactly it! I did not realize | ft user was including other info not just the value of the attribute.”
I don’t think you understand what was being said here.
whenever you format output, you immeidately lose the object, and wind up with a string of text.
To understand this run the following commands to see what output you are recieving and what type of ojbect is being returned.
get-pswho | ft user|get-member
get-pswho |get-member
the first command will show you that you have a string after you perform the ft (this is an alias for format-table)
not sure to be honest the object type your function is designed to return, but it will have appropriate properties that can be addressed to build a pscredential object.
but this is a fundamental point of powershell, it is object oriented.