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.
De antemano gracias por la ayuda.
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.
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.
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
Buenos dias Estimado,
La captura de pantalla es el error actual que te esta dando ahora?
Saludos,
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:
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
Un saludo,
Pablo
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.
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.
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.