header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Scheduled Powershell scripts not passing authentication to Connect-VIServer
Last Post 23 Oct 2009 08:56 PM by halr9000. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RichardL1User is Offline
New Member
New Member
Posts:7
Avatar

--
08 Oct 2009 06:43 AM
    I have a Powershell script that captures VMware metrics. This uses Connect-VIServer to make the connection to Virtual Center. If I run the script interactively it will pass through authentication without me using the username and password parameters on the Connect-VIServer command (Connect-VIServer -server servername). If I take the same script and run it as a scheduled task (running task under same user context) it will fail. The only way I have got it to run is to add the username and PW parameters to the Connect-VIServer command which means the username and PW are stored in the script - obviously an unacceptable situation.

    Any ideas?
    RichardL1User is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    21 Oct 2009 07:21 AM
    I will answer my own question as I'm sure others will run into this issue with their schedule tasks.

    http://professionalvmware.com/2009/...l-storage/

    To create the credcential file run this:
    New-VICredentialStoreItem -host 'servername.com' -user 'domain\fredsmith' -password 'blahblah1' -file \\servername\sharename\Credfile.xml

    To view the credentials in the credentials file run this:

    $creds = Get-VICredentialStoreItem -file "\\servername\sharename\Credfile.xml"
    $creds | fl *

    To use the credentials run this:
    $creds = Get-VICredentialStoreItem -file "\\servername\sharename\Credfile.xml"
    Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password

    You can put multiple credentials in the same encrypted credential file. To connect to each server in a multi credential file run this:

    ForEach ($creds in $credentials) {
    Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password
    # Do other stuff here...
    }

    Enjoy - Richard
    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    23 Oct 2009 08:56 PM
    Thanks for posting the answer!
    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer