Hello.
I have created this simple ASP page to interact with PowerCLI. This script works fine, only if I put in my credenitals in the Connect-VIServer cmdlet. I would like to use the Credentials Store to supply the Username and password... mainly the password.
I created a credential store using the New-VICredentialStoreItem,
copied the .xml file to the systemprofile appdata directory( on Windows 2008 Server it's c:\windows\system32\config\roaming\appdata\vmware\credstore).
I am
unable to get the script to work. It bombs at the connect-viserver
cmdlet. The error message is : *+The method or operation is not
implemented.+*
Here's the code:
<html>+ + <head>+ + </head>+ + <body>+ + <% Add-PSSnapin VMware.VimAutomation.Core %>+ + <% $credentials=Get-VICredentialStoreItem -Host vcenter %>+ + <% Connect-VIServer -Server vcenter -User $credentials.User -Password $credentials.Password %>+ + <table>+ + <tr>+ + <% Get-VM | where {%>+ + <td><% ($_ | get-networkadapter).NetworkName -eq "Virtual Machine Network"%></td>+ + <td><% } | ft name, powerstate %></td>+ + </tr>+ + </table>+ + </body>+ </html> +
Have you successfully used the Get-VICredentialStoreItem with your ps1x pages?
Thanks,
Tim T
You'll have to translate it into ASP, but I have used this construct in PowerShell successfully, and I think it'll help.
$username = 'myUser' ## How to create the encrypted password file used in this script $c=get-credential $username $cf = Join-Path (Split-Path $profile) stored_credential.txt $c.Password | ConvertFrom-SecureString | Set-Content $cf ## Use stored password file $cf = Join-Path (Split-Path $profile) stored_credential.txt $p = Get-Content $cf | ConvertTo-SecureString $c = New-Object System.Management.Automation.PsCredential $username,$p ## Connect to vCenter Connect-VIServer -Server $vc -Credential $c
Doug,
This script worked great in the PS Console, however it didn't in PowerShellASP. I am thinking that PowershellASP doesn't know how to handle the encryption, therefore it errors out. I think I am going to hold off from making my interactive scripts ASP pages for now. Or put less focus on it until MS or VMWare adopts it. It would VERY cool.
BTW, when using PowershellASP, your code does between <% %> tags. Easy as that. The output would be formatted with HTML.
Thanks for your response. I like your code because it asks the user to put in their credentials. This eliminates the need of a service account and the accidental execution of a script.
Tim T.
This is a limitation of PowershellASP. I responded to your post on vmwarescripting.com.