Release of connect-viserver added to the variable - how?

Hello

I'm fighting to understand a problem with a script that I write to stop our vSphere & NetApp infrastructure when our UPS battery is critical.  If someone would be so kind help where I am wrong, I would be happy.

A function connects to vSphere, gets the list of running virtual machines and this output to a csv file.  The value of the csv path is then returned by the function to be used elsewhere in the script.

The problem I encounter is that the output of the command connect-viserver is being added for the returned data, and so I did not have a clean file to a csv file name more.  When I put a breakpoint on the return line, the value of $RunningVM_File is: C:\Path\To\file.txt, continue the script and check the value of the variable of the function is returned to, and the returned value has changed:

Port of user name

----                           ----  ----

vCenter_Server_NAme 443 domain\username

C:\Path\To\file.txt

Here is the function of the origin of the problem:

function Initialize-vSphereShutdown

{

[CmdletBinding()]

[OutputType ([string])]

Param

(

# Description helps Param1

[Parameter (mandatory = $true,)]

ValueFromPipelineByPropertyName = $true,

Position = 0)]

$vSphereServer,

# Description helps Param2

[string]

$BasePath,

[pscredential]

$Credential,

# Description helps Param

[Parameter]

[string] $Logfile

)

Begin

{

#Connect to vSphere

SE connect-VIServer-Server $vSphereServer - Credential $Credential # - User $UserName - Password $Password

Write-debug ' connected to: $vSphereServer.

Write-output ((Get-Date-f o) +"- connected to vCenter / ESXi host:"+ $vSphereServer) | out-file $Logfile - Append

$RunningVM_File = ($BasePath) + "RunningVMs.txt".

}

Process of

{

If (Test-Path ($RunningVM_File)) {}

Remove-Item ($RunningVM_File)

}

#Return list of all ESXi hosts managed by the host connected/vCenter

$ESXiSRV = get-VMHost | Select-Object - ExpandProperty name | Out-string

Write-debug ' following ESXi hosts are available:

$ESXiSRV write-debug

Write-output ((Get-Date-f o) +"- the following ESXi hosts are available:"+ $ESXiSRV) | out-file $Logfile - Append

$vCenterESXiHost = get-VMHost - VM $vSphereServer | Select-Object - ExpandProperty name | Out-string

$vCenterESXiHost | Out-file ($BasePath + "vCenterESXiHost.txt")

Write-debug ' vCenter Server running on host: $vCenterESXiHost.

Write-output ((Get-Date-f o) +' - vCenter Server running on the host: "+ $vCenterESXiHost) | out-file $Logfile - Append

Debugging of Scripture "implementation of virtual machines.

$RunningVM = get - VM | Where-Object {$_.} PowerState - eq "Receptor"} | SELECT name, folder, VApp

$RunningVM | Export-Csv $RunningVM_File - NoTypeInformation

Write-debug ' list of virtual computers running sauvΘs: $RunningVM_File.

Write-output ((Get-Date-f o) +' "-list of virtual machines running recorded at:" + $RunningVM_File) | out-file $Logfile - Append

}

End

{

return $RunningVM_File

}

}

Send the output of the cmdlet COnnect-VIServer into a black hole ;-)

Like this

SE connect-VIServer-Server $vSphereServer - Credential $Credential # - User $UserName - Password $Password | Out-Null

Tags: VMware

Similar Questions

  • my intranet connection was turned off the coast how I turn it back on?

    my intranet connection was turned off the coast how I turn it back on? (or my wireless connection)  I tried to click the wifi icon but it just says that it is not connected.

    Hi karmahome,

    Follow these steps:

    1. click on the button "Start" and then click on the "Control Panel" icon in the start menu.

    2. click on the link "switch to category view" in the left pane of the Control Panel window if the window is not already assigned to the category view. You will see the 'network connections' icon in the right pane. Double-click this icon to open the network connections window.

    3 right-click on the icon of the adapter wireless network in the network connections window, then click the "Properties" link in the context menu. This opens the wireless network connection control panel.

    4. click on the "wireless networks" tab in the wireless network connection control panel. Check the box 'use Windows to configure my wireless network'.

    5. click on the 'OK' button in the wireless network connection control panel.

    For reference:

    How to troubleshoot wireless network connections in Windows XP Service Pack 2

    http://support.Microsoft.com/kb/870702

  • Pass the credentials to connect-VIServer

    Hey all,.

    I give my first ride with scritping with powercli. I have currently a "script" that consists of two one liners, first line is to remove a virtual machine and the second line is to create a virtual machine from a clone. Nothing major, I know. I'm trying to understand, what I would plan this script as a Windows task and pass the credentials used to run the task to the cmdlet Connect-VIServer I at the beginning of the scipt.

    Someone help a rookie?

    TIA,

    -Jason

    Why not let the scheduled task run with this specific account?

    In this way, you don't have to pass the credentials to the cmdlet Connect-VIServer, it uses the credentials of the user under which the scheduled task runs.

    If the above is not possible and you must pass credentials, take a look at Hal functions PSCredential-export and import-PSCredential.

    These jacks allow the use the credentials in a secure manner that pass them in clear text in your script.

  • Running PowerCLI connect VIServer & Get - VM as a single command

    I'm trying to create a script that allows me to generate the results of the cmdlet 'get - vm | Get-snapshot | format-list' in a file


    I use a piece of software that allows us to run scripts remotely via commands or PowerShell prompt


    How can I create a single command line that would Connect-VIServer vCenterServerName order & the get - vm | get-snapshot | format-list?


    I add variables via our software for the name of user and password & vmware server IP. These variables must be part of the command, for example:


    SE connect-VIServer-Server @VMwareHostIP @ - protocol https - User @Username @ - Password @Password @.


    Is there a way I could call the PowerCLI from the Windows command prompt?

    You can try below to the command prompt

    PowerShell "add-pssnapin vmware.vimautomation.core"; ' Connect-VIServer-Server @VMwareHostIP @ - protocol https - User @Username @ - Password @Password @; ' get - vm | Get-snapshot | format-list.

    Separate each command with ';' and best practices is Quote unquote each order.

  • Custom Connect-VIServer System.OutOfMemoryException

    Hello

    I try to use PowerCLI on a remote server, using Enter-PSSession.

    Here are the steps I take:

    1 enter-PSSession < servername > - Credential < username >

    2 add-PSSnapin - name:VMWare.VimAutomation.Core

    3 connect-VIServer < VIServername >

    Then, I get this error:

    Connect-VIServer: 01/01/2012 18:54:27 connect - VIServer Exception from the

    of type 'System.OutOfMemoryException' was thrown.
    + CategoryInfo: NotSpecified: (:)) [connect-VIServer], ViError)
    + FullyQualifiedErrorId: Client20_ConnectivityServiceImpl_Reconnect_Excep
    tion, VMware.VimAutomation.ViCore.cmdlets.Commands.ConnectVIServer

    If I do all the above steps locally on the server that I am PS Remoting for, it all works very well... I hope that there are only a few space change of parameter or the memory that I can do to make it work.

    I tried communication distance to 2 servers various and also tried PowerCLI 4.1.1 and 5.0.

    Thanks for any help that anyone can provide.

    Dan

    This could be the memory limit when you do remoting of PS.

    Try the fix described in access remote of memory exception

  • How can I get my icon of network connectivity added to the notification (to the left of the date) area?

    original title: Hello, how can I get my icon of network connectivity added to the notification (to the left of the date) area?   Thank you, NT

    The icon disappeared after stopping at the wall accidentally. When I right click on the taskbar, go into the properties box and notification, network system icon is grayed out.

    Thanks for your help.

    Hi NT,

    You can read the following article and check if it helps.

    System icons do not appear in the notification area in Windows Vista or Windows 7, you must restart the computer

    You can also consult the following articles and check.

    Show all icons in the notification area (system tray)

    Remove icons from the notification area (system tray)

    Hope this information is useful.

  • What is the minimum privileges that I return so he can make a Connect-VIServer and a Get - VM?

    Hi all

    I'm writing a small script to list all our virtual machines.

    I want installation service account just for that and I want to give to these minimum permissions accounts: just enough to Connect-VIServer and a Get - VM.

    Should what minimum privileges I give?

    How could I have figured this out on my own?

    Thanks in advance!

    -Chris


    Read only role applied to the vCenter node.

  • Connect-VIServer throws the invalid URI error in the Studio of Powershell, but is very well outdoors

    I don't know if it's a problem of Powershell Studio 2014 or PowerCLI, but other people have reported the "invalid URI: the hostname could not be parsed" error, so I'll start here.

    I have a PowerCLI 5.0.1 on Windows 7, Powershell v2.0 and Powershell Studio 2014.

    In my script, when I run the Connect-VIServer-Server $server command, the command fails and generates the invalid URI error.  However, when I run my script in the command window PowerCLI, the script works fine.

    I guess I have a problem of environment in the Studio of Powershell, but wonder what circumstances causes PowerCLI to raise this error.

    So far, I have not had much luck with Studio 2014 Powershell and PowerCLI, don't know if it's powershell v2.0 or something else.

    It looks like a Studio of Powershell environment problem.

    I have many ps1 files and use the point of supply to load the files ps1 in support which includes the call to connect-VIServer.  When I put the connect-VIServer in the file main ps1 I can connect to my vCenter, but when I put in the origin file, I cannot connect, nor can fact the fitting of test-work order.

    Thanks for the help.

  • How to make the Connect-VIServer cmdlet to always ask for username password

    Hi all

    I use the connect-viserver cmdlet to connect between host windows to my vcenter server.

    using

    The host - Powershell - 2.0, Windows XP, Powercli installed machine.

    Target machine - Vcenter server 4.1.0 on windows 2008 server, in the other subnet

    I want to have a provision that it must always ask for user name and password to connect.

    I took a look at

    http://pubs.VMware.com/vSphere-50/index.jsp?topic=/com.VMware.wssdk.apiref.doc_50/Vim.virtualmachine.html

    resultof = % 22connect - viserver % 22 & http://pubs.VMware.com/vSphere-50/index.jsp?topic=/com.VMware.PowerCLI.cmdletref.doc_50/connect-VIServer.html

    But failed to get the relevant information.

    Any ideas?

    Thank you

    Madalena

    Bangalore-India

    My mistake, Connect-ViServer does not accept a SecureString. You first need to convert it

    Try it like this

    $userName = "username"
    $passwd = Read-Host ("Password for " + $userName) -AsSecureString:$true
    $cred = New-Object System.Management.Automation.PSCredential -ArgumentList $userName,$passwd
    Connect-VIServer -Server MyServer -Credential $cred
    
  • Save the Connect-VIServer session between scripts?

    In order to make the GUI for people who are not used to the command line, we want to look at aid where VBScript code call scripts powershell to work behind the scenes of the HTA.  The only problem is the delay of connecting to VIServer for what the user does.  Say they click on a button for a list of the virtual machine, it could trigger a ps script which collects and posts this info using the Clipboard.  After that, however, that the script is closed and therefore the session.  The button depending on whether they click should also have a sign at the beginning of the script, accompanied by another 10 seconds to wait on the connection.  Is there a way to store/save the session so that we can connect onload of the code of the road and all the following scripts could continue with this session?

    Thank you

    Josh

    Keep the open sessions is not a good idea imho, and the maximum number of sessions is limited.

    Have you tried all the known solutions to accelerate the PowerCLI process?

    Another possible way is to use a central script that runs continuously in the background and you submit orders from your application to this central script through a sort of semaphores (this could be simple files in a specific folder for example).

    Update: there used to Save Session and Load-Session cmdlets in previous versions of PowerCLI, but these were dropped.

  • Ideas re: ' Connect-VIServer: could not connect using the requested protocol "failure

    I know, it's a matter of weakness, but I hit the wall on this one. I've even got desperate enough that bouncing private LuD, and I tried everything we discussed, but I'm still @ deadlocked.

    I developed and tested several scripts that I am finally ready to go with Prod.

    I get this error when I am trying to connect to Vcenter server or host of the cmndline of vitoolkit (and obviously in scripts).

    «Connect-VIServer: could not connect using the requested protocol.»

    I'm runing the vitoolkit FROM the server VCenter, so I wouldn't exepct the local to be a problem connection. I expect calls the ESX servers as questions) (we have several firewalls in the game). But even once, on-site I would not expect a problem.

    I checked my ports of VC and even more precisely called listener in the connect command, but it does not help.

    I tried to watch the ports through various lines of command, but I don't see anything.

    Any suggestions?

    Add - confirm: $false and it won't be quick.

    =====

    Carter Shanklin

    Read the PowerCLI Blog
    [Follow me on Twitter |] http://twitter.com/cshanklin]

  • Extraction of SSL with initial Connect-VIServer

    Sorry if this has already been asked before, but I was not able to find it by searching online or in the forums.

    When you start a connection to another host of VC/ESXi, there is some information about x 509 certificate as shown below.

    * The X 509 chain could not be achieved with the root certificate.

    Certificate: [subject]

    C = US, CN = vcenter60 - 4.primp - industries.com

    [Issuer]

    O = vcenter60 - 4.primp - industries.com, C = US, DC = local, DC = vghetto, CN = CA

    [Number]

    00D9B9AE28CFD6CF4D

    [Not before]

    02/08/2015-09:19:14

    [Not After]

    02/02/2025 09:19:13

    [Imprint]

    B846B9F36C1D978CEDA0199294E61B4515656396

    I would like to enter the thumbprint SSL "B846B9F36C1D978CEDA0199294E61B4515656396"? I looked online and even asked some people but never able to retrieve this property by using PowerShell/PowerCLI. I can do it easily on one other system Windows with openssl (http://www.virtuallyghetto.com/2012/04/extracting-ssl-thumbprint-from-esxi.html), but wanted to see if there is a way without going through relays on the external packaging and since it is available as part of the connect-VIServer, I thought it must be possible but my PowerCLI-Fu isn't quite at the height as the others , figure so I ask. If it is indeed removable, which I guess it is then a bonus would be to format and so I have a variable that looks like: B8:46:B9:F3:6 C: 1 d: 97:8 C: ED: A0:19:92:94:E6:1 B: 45:15:65:63:96


    Luc Merci in advance

    Function Test-WebServerSSL {
    # Function original location: http://en-us.sysadmins.lv/Lists/Posts/Post.aspx?List=332991f0-bfed-4143-9eea-f521167d287c&ID=60
    [CmdletBinding()]
        param(
            [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
            [string]$URL,
            [Parameter(Position = 1)]
            [ValidateRange(1,65535)]
            [int]$Port = 443,
            [Parameter(Position = 2)]
            [Net.WebProxy]$Proxy,
            [Parameter(Position = 3)]
            [int]$Timeout = 15000,
            [switch]$UseUserContext
        )
    Add-Type @"
    using System;
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    namespace PKI {
        namespace Web {
            public class WebSSL {
                public Uri OriginalURi;
                public Uri ReturnedURi;
                public X509Certificate2 Certificate;
                //public X500DistinguishedName Issuer;
                //public X500DistinguishedName Subject;
                public string Issuer;
                public string Subject;
                public string[] SubjectAlternativeNames;
                public bool CertificateIsValid;
                //public X509ChainStatus[] ErrorInformation;
                public string[] ErrorInformation;
                public HttpWebResponse Response;
            }
        }
    }
    "@
        $ConnectString = "https://$url`:$port"
        $WebRequest = [Net.WebRequest]::Create($ConnectString)
        $WebRequest.Proxy = $Proxy
        $WebRequest.Credentials = $null
        $WebRequest.Timeout = $Timeout
        $WebRequest.AllowAutoRedirect = $true
        [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
        try {$Response = $WebRequest.GetResponse()}
        catch {}
        if ($WebRequest.ServicePoint.Certificate -ne $null) {
            $Cert = [Security.Cryptography.X509Certificates.X509Certificate2]$WebRequest.ServicePoint.Certificate.Handle
            try {$SAN = ($Cert.Extensions | Where-Object {$_.Oid.Value -eq "2.5.29.17"}).Format(0) -split ", "}
            catch {$SAN = $null}
            $chain = New-Object Security.Cryptography.X509Certificates.X509Chain -ArgumentList (!$UseUserContext)
            [void]$chain.ChainPolicy.ApplicationPolicy.Add("1.3.6.1.5.5.7.3.1")
            $Status = $chain.Build($Cert)
            New-Object PKI.Web.WebSSL -Property @{
                OriginalUri = $ConnectString;
                ReturnedUri = $Response.ResponseUri;
                Certificate = $WebRequest.ServicePoint.Certificate;
                Issuer = $WebRequest.ServicePoint.Certificate.Issuer;
                Subject = $WebRequest.ServicePoint.Certificate.Subject;
                SubjectAlternativeNames = $SAN;
                CertificateIsValid = $Status;
                Response = $Response;
                ErrorInformation = $chain.ChainStatus | ForEach-Object {$_.Status}
            }
            $chain.Reset()
            [Net.ServicePointManager]::ServerCertificateValidationCallback = $null
        } else {
            Write-Error $Error[0]
        }
    }
    
    $cert = Test-WebServerSSL MYVC
    $cert.Certificate.Thumbprint
    
  • to connect-viserver to several viservers @ simultaneously fails

    Hello

    because they are forced to leave related modes, we cannot use the connect-viserver - alllinked more...

    If google told me to use connect-viserver vc1, vc2

    You can check this, if you check the $global value: DefaulViServers

    In my case, there is only the vc2 listed, even if the connection to the two vcenters works very well...

    Version is 5.1 Release 1 PowerCLI

    Why?

    THX in advance

    Chakoe

    Add the parameter Scope

    Game-PowerCLIConfiguration - multiple DefaultVIServerMode - Scope Session

  • Impossible to use Connect-VIServer

    I have two machines, both with PowerCLI 5.1 R1. A machine is Server 2003 with .net 2.0 SP1, 3.0 SP1 .net, and installed .net 4 (call this server1). The other machine is Windows 7 with .net installed 4.5 (let's call this Station1). The machine called server1 is also the vCenter Server

    When I opened PowerCLI to Workstation1, it connects fine. When I opened PowerCLI on server1, I get the following error:

    SE connect-VIServer: method not found: ' Int32 System.Threading.WaitHandle.WaitAny
    (System.Threading.WaitHandle [], Int32) ».
    On line: 1 char: 17
    + Connect-VIServer < < < < server1
    + CategoryInfo: NotSpecified: (:)) [connect-VIServer], MissingMet)
    hodException
    + FullyQualifiedErrorId: System.MissingMethodException, VMware.VimAutomati
    on.ViCore.Cmdlets.Commands.ConnectVIServer

    What Miss me?

    Thank you.

    Install this package, which includes .net Framework 3.5, but also the latest service packs for 2.0 and 3.0.

    http://www.Microsoft.com/en-US/Download/details.aspx?ID=25150

    Then I would also download .NET framework of Microsoft security patches, as there were some published since these versions of .NET have been released.

  • Parameter IN or OUT to missing index: 1 using the variable date ODI.

    Hello

    I created the variable of data type date as EXTRACT_FROM_TS and also the default value for this.
    Now I use this variable as a filter in the source table in the design of the Interface as below...
    LAST_UPDATE_DATE > = #p_extract_from_ts where LAST_UPDATE_DATE is the field in the source database with date data type not null not forced...
    I have lkm hv used SQL for Oracle...

    Above variable refresh and interface scenario running one after another in ODI package...
    Variable gets refresh every time successfully, but Interface fails at the step of loading data... error message as below...


    ODI-1227: SrcSet0 (load) task fails on the source of ORACLE R12DEV connection.
    Caused by: java.sql.SQLException: parameter IN or OUT to missing index: 1
    + oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1890) +.


    If we remove the filter LAST_UPDATE_DATE > = #p_extract_from_ts, then it works well...

    I do not know why this error pops up on adding filter... Please help on this...


    Thank you
    Roshan Y

    Hello

    put a step DECLARATION above all. After that in my opinion, it is better to put a TO_CHAR().

    Try putting your variable in text mode and change your filter in

    TO_CHAR (LAST_UPDATE_DATE, 'YYYYMMDDHHMI') > = TO_CHAR(#PROJ.) P_EXTRACT_FROM_TS, "YYYYMMDDHHMI")

    In your operator if you click on the variable whose value you see?

Maybe you are looking for

  • I can stop all my addons disabled whenever it updates of Firefox?

    Whenever Firefox updates, it disables all my addons and presents me with a line of tabs, in which I need to check a checkbox, click a button to continue and select restart, or not, for each of the addons. I think I do something wrong, because surely

  • Wait (ms) function and Cicles

    Hi, I want to give an expectation of my VI (that would be 1 second even as 1 HR or more). I've been using the wait function, but I want to know is if it's possible to program a break so that the user can interrupt the VI before the end of the wait fu

  • 4 Windows7 VideoCam HP Envy laptop

    I have not used my webcam for a while, but recently updates to Skype. When I went to use the web cam, it was not detected. When I try Cyberlink Ucam it says no webcam detected. I checked the driver in Device Manager, and it's ok. I used HP Recovery M

  • Laptop HP 630, generic peripheral MIDI usb not recognized

    I have a problem with a laptop HP 630 of all nine (clearance stock) (LV425PA #ABG): this is not to recognize a generic USB MIDI device (keyboard). When the unit is plugged in, I get a message "USB device not recognized". He calls an "unknown device"

  • How can I translate from English to the french when I send messages in outlook express 6?

    Original title: translate in Outlook Express 6 I would like to correspond with my french friends in their language.  How can I translate from English to the french when I send them messages?  A free way to do this would be the best option that I do n