VMware Global Community
fabianalarcon
Enthusiast
Enthusiast
Jump to solution

Ayuda...... con problemas de ejecución de script en PowerCli 5.1

The Gurus,

Actualmente me encuentro desarrollando un laboratorio en el cual tengo que ejecutar un script en PowerCli 5.1 y no me permite realizar la ejecución del mismo en la imagen se muestra el error.

Error_Script.png

De antemano gracias por la ayuda.

Reply
0 Kudos
1 Solution

Accepted Solutions
TronAr
Commander
Commander
Jump to solution

Ese error es por una función no definida.

El script en cuestión es del lab de troubleshooting workshop, y la función está definida en un profile de powerShell.

Si estabas en el curso, el problema puede ser que te hayas identificado con un usuario que no es el del dominio.

View solution in original post

7 Replies
sanmarfe
Expert
Expert
Jump to solution

Estimado, buenos días.

Aparentemente hay algún problema en tu script.

Podrías adjuntar el script completo para poder analizarlo?

Saludos cordiales,

S.G.

Sanmarfe. VMware Certified Professional VCP3/VCP4/VCP5 VTSP4 / VTSP5 Si esta u otra respuesta es util, por favor marca su correspondiente notificador. Gracias/Regards
Reply
0 Kudos
fabianalarcon
Enthusiast
Enthusiast
Jump to solution

Hola Sanmafe,

De antemano gracias por interesarte en el tema, dejo el codigo del Script para poderlo verificar:smileyconfused:.

Se esta quedando en el else (  Write-Warning "UNEXPECTED ERROR: Script configuration file missing`nSeek help from your instructor.")

Inicío de Script

# break-5-1.ps1

# This script breaks the the Virtual machine production network

# by removing the nic from vSwitch.

#

$scriptpath = $MyInvocation.MyCommand.Path

$directorypath = Split-Path $scriptpath

$netfile = $directorypath + "\net_commands.ps1"

Import-Module $netfile

Write-Host -NoNewline "Please wait while the system is prepared for your exercise. . . "

Set-PowerCLIConfiguration -confirm:$false -InvalidCertificateAction Ignore | Out-Null

# #######

# Confirm that this script is being run as Administrator

# #######

If (-NOT ( running_with_privilege ) )

{

    Write-Warning "FAIL: YOU ARE NOT READY TO START THE LAB`nThis script must be run as an Administrator!"

    Exit

}

# #######

# Load global variables, connect to vCenter Server

# #######

If ($classdatafile -and ( Test-Path $classdatafile) ) {

  [xml]$classInfo = Get-Content $classdatafile

} else {

  Write-Warning "UNEXPECTED ERROR: Script configuration file missing`nSeek help from your instructor."

  Exit

}

$vc = $classInfo.Class.vc.Name

If ($credentialfile -and ( Test-Path $credentialfile) ) {

    $credential = Get-VICredentialStoreItem -Host $vc -File $credentialfile

    trap {

    write-warning ("UNEXPECTED ERROR: After reading credential file`n" + $_.Exception.message)

    Exit

    } Connect-VIServer $vc -User $credential.User -Password $credential.Password -ErrorAction Stop | Out-Null

} else {

  $credential = Get-Credential

  trap {

    write-warning ("UNEXPECTED ERROR: After accepting credential interactively`n" + $_.Exception.message)

    Exit

    } Connect-VIServer $vc -Credential $credential | Out-Null

}

Write-Debug "Finished script initialization"

Write-Host -NoNewline "."

#Write-Host "Executing script"

#Import-Module "c:\Documents and settings\Administrator.vclass\My Documents\WindowsPowerShell\net_commands.ps1"

#this is the locaton of the file on the hard disk should be the only hardcoded variable in the script

#$xmlfile = "C:\Tools\ClassInfo.xml"

# Open the file that contains the varibles used for this script.

#[xml]$classInfo = OpenXMLFile $xmlfile

#Open the xmlfile

#set the various variables that will be used in the script

#$vc = $classInfo.Class.vc.name

#$vcUser = $classInfo.Class.vc.user

#$vcPass = $classInfo.Class.vc.password

$MyEsx = $classInfo.Class.Host[0].name

$PartnerEsx = $classInfo.Class.Host[1].name

$vS2 = $classInfo.Class.Module5.Switches.Switch2.name

$pg = $classInfo.Class.Module5.Switches.Switch2.pg

#Connect to the Virtual Center Server

#$srv= ConnectToVC $vc $vcUser $vcPass

##If the virtual machines are powered off then power them on

Get-Vm | where {$_.Powerstate -eq "PoweredOff"} | Start-VM -Confirm:$false | out-null

#See where the virtual machines are located and move them to production if

#they are located somewhere else.

$vmpg = Change_VMPortgroup $pg

#This breaks the NIC on the Production Network by removing the NIC from the vSwitch

$h = Get-VMHost $MyEsx

$nic = @()  #Empty array

  Foreach ($s in Get-VirtualSwitch -Standard ) {

  if ($s.Name -eq $vS2) {

  Set-VirtualSwitch $s -Nic $nic -Confirm:$false  | Out-Null

  } #end if

  } #end foreach

Disconnect-VIServer -Confirm:$false

Write-Host

Write-Host "You are now ready to start the lab"

break ;

#Disconnect-VIServer -Confirm:$false

Reply
0 Kudos
sanmarfe
Expert
Expert
Jump to solution

Buenos dias Estimado,

La captura de pantalla es el error actual que te esta dando ahora?

Saludos,

Sanmarfe. VMware Certified Professional VCP3/VCP4/VCP5 VTSP4 / VTSP5 Si esta u otra respuesta es util, por favor marca su correspondiente notificador. Gracias/Regards
Reply
0 Kudos
Borja_Mari
Virtuoso
Virtuoso
Jump to solution

Hola,

tu script (por el motivo que sea), necesita ser ejecutado con permisos de administrador.

Además el script no reconoce la variable "running_with_privilege" ( ¿¿ donde se define valor para esa variable ??)

Yo lo que haría en tu caso seria lo siguiente:

  1. Asegurarte de ejecutar el script como Administrador (Siendo el propio usuario Administrador/Administrator o con un usuario dentro del grupo Administradores)
  2. Borrar la parte del código que comprueba el "running_with_privilege":

If (-NOT ( running_with_privilege ) )

{

    Write-Warning "FAIL: YOU ARE NOT READY TO START THE LAB`nThis script must be run as an Administrator!"

    Exit

}

Para mi lo que comento de hacer sería lo más sencillo.

Espero haberte sido de ayuda Smiley Wink

Un saludo,

Pablo

------------------------------------------------------------------------------------------------- PLEASE CONSIDER AWARDING any HELPFUL or CORRECT reply. Thanks!! Por favor CONSIDERA PREMIAR cualquier respuesta ÚTIL o CORRECTA . ¡¡Muchas gracias!! VCP3, VCP4, VCP5-DCV (VCP550), vExpert 2010, 2014 BLOG: http://communities.vmware.com/blogs/VirtuallyAnITNoob
Reply
0 Kudos
xacolabril
Expert
Expert
Jump to solution

Ciertamente no sé de dónde sale ese "running_with_privilege". Parece una variable de sesión o algo similar, pero que ciertamente está molestando en el inicio del script.

Como bien dice Borja_Mari, la primera idea sería eliminar esa parte de código.

Saludos.

Xavier Colomé Abril. VMware Certified Professional VCP3, VCP4 and VCP5. [Si encuentras que esta o cualquier otra respuesta ha sido de utilidad, vótalas. Gracias.] [If you find this or any other information helpful or correct, please consider awarding points. Thank you.]
TronAr
Commander
Commander
Jump to solution

Ese error es por una función no definida.

El script en cuestión es del lab de troubleshooting workshop, y la función está definida en un profile de powerShell.

Si estabas en el curso, el problema puede ser que te hayas identificado con un usuario que no es el del dominio.

fabianalarcon
Enthusiast
Enthusiast
Jump to solution

Mi estimado TronAr

Es muy acertada tu respuesta mil disculpas por tardar en responder y dar las respectivas valoraciones, el tema estaba en que el Script llamaba a un archivo el cual contiene los valores de los parámetros que debía pasar dentro de las lineas del Script, y no estaba ni en la rita que debia estar, no contaba con los privilegios la consola y adicional no se había customizado los valores por todas estas anteriores se generaba un error, me costo un tanto de trabajo entender pero finalmente lo logre y los Labs funcionaron correctamente.

Nuevamente muchas gracias por su ayuda.

Reply
0 Kudos