Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

Error "operation requires an interactive window station" when using Invoke-VMScript

$
0
0

I have a Ranorex test which runs successfully when running it, directly, on a VM.

When calling this test remotly, by using Invoke-VMScript (running a batch file that calls the test), it fails with "operation requires an interactive window station".

I have administrator privileges on the computer.

 

Any idea what am I doing wrong?


How to find ESX hostnames from distributed switch query

$
0
0

I seem to be going round in circles on this one.

 

Is there an easy way to to query the vDS and return the hostnames of the connected ESX hosts?

 

I can get it using Moref via the following kind of thing:

 

 

Get-VDSwitch | ForEach {

    $SwMORefs = $_.ExtensionData.Config.host.config.host.value

    $SwitchName = $_.Name

    $SwitchName

    ForEach ($MR in $SwMORefs) {

        $AttachedHost = Get-VMHost | Where {$_.ExtensionData.MoRef -match $MR}

        $AttachedHost

    }

}

 

 

 

...but this seems a bit complex and slow?

Not Writing invoke output

$
0
0

I am trying to fetch the patch,AV and application service status using invoke cmdlet. Its failing to write the output.

If I try to get McAfee and Service status its displaying the output but for the third script which is failing to write output($hotfixinfo).

If I log in to the VM manually and execute it I can get the output.

 

$script = @' 
if([IntPtr]::Size -eq 8){    $text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |        %{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 4){    $text = Get-ItemProperty -Path "HKLM:\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |        %{"$($_.AgentGUID)"}
}
if(-not $text){    $text = Get-Service -Name "McAfee Framework Service" -ErrorAction SilentlyContinue | %{"$($_.Name) is $($_.Status)"}    if(-not $text){        $text = Get-Service -Name wuauserv | Select -First 1 |            %{"$($_.Name) is $($_.Status)"}    }
}
$cbout = Get-Service -Name "CarbonBlack" -ErrorAction SilentlyContinue | Select -first 1 | %{"$($_.Name) is $($_.Status)"} 
if(-not $cbout){     $cbout = Get-Service -Name wuauserv | Select -first 1 | %{"$($_.Name) is $($_.Status)"} 
}
$hotfixinfo=@()
[reflection.assembly]::LoadWithPartialName("System.Version")
$os = Get-WmiObject -class Win32_OperatingSystem
$osName = $os.Caption
$s = "%systemroot%\system32\drivers\srv.sys"
$v = [System.Environment]::ExpandEnvironmentVariables($s)
If (Test-Path "$v")    {    Try        {        $versionInfo = (Get-Item $v).VersionInfo        $versionString = "$($versionInfo.FileMajorPart).$($versionInfo.FileMinorPart).$($versionInfo.FileBuildPart).$($versionInfo.FilePrivatePart)"        $fileVersion = New-Object System.Version($versionString)        }    Catch        {       $hotfixinfo+= "Unable to retrieve file version info, please verify vulnerability state manually."        Return        }    }
Else    {   $hotfixinfo+= "Srv.sys does not exist, please verify vulnerability state manually."    Return    }
if ($osName.Contains("Vista") -or ($osName.Contains("2008") -and -not $osName.Contains("R2")))    {    if ($versionString.Split('.')[3][0] -eq "1")        {        $currentOS = "$osName GDR"        $expectedVersion = New-Object System.Version("6.0.6002.19743")        }     elseif ($versionString.Split('.')[3][0] -eq "2")        {        $currentOS = "$osName LDR"        $expectedVersion = New-Object System.Version("6.0.6002.24067")        }    else        {        $currentOS = "$osName"        $expectedVersion = New-Object System.Version("9.9.9999.99999")        }    }
elseif ($osName.Contains("Windows 7") -or ($osName.Contains("2008 R2")))    {    $currentOS = "$osName LDR"    $expectedVersion = New-Object System.Version("6.1.7601.23689")    }
elseif ($osName.Contains("Windows 8.1") -or $osName.Contains("2012 R2"))    {    $currentOS = "$osName LDR"    $expectedVersion = New-Object System.Version("6.3.9600.18604")    }
elseif ($osName.Contains("Windows 8") -or $osName.Contains("2012"))    {    $currentOS = "$osName LDR"    $expectedVersion = New-Object System.Version("6.2.9200.22099")    }
elseif ($osName.Contains("Windows 10"))    {    if ($os.BuildNumber -eq "10240")        {        $currentOS = "$osName TH1"        $expectedVersion = New-Object System.Version("10.0.10240.17319")        }    elseif ($os.BuildNumber -eq "10586")        {        $currentOS = "$osName TH2"        $expectedVersion = New-Object System.Version("10.0.10586.839")        }    elseif ($os.BuildNumber -eq "14393")        {        $currentOS = "$($osName) RS1"        $expectedVersion = New-Object System.Version("10.0.14393.953")        }    elseif ($os.BuildNumber -eq "15063")        {        $currentOS = "$osName RS2"   $hotfixinfo+="No need to Patch. RS2 is released as patched. "        return        }    }
elseif ($osName.Contains("2016"))    {    $currentOS = "$osName"    $expectedVersion = New-Object System.Version("10.0.14393.953")    }
elseif ($osName.Contains("Windows XP"))    {    $currentOS = "$osName"    $expectedVersion = New-Object System.Version("5.1.2600.7208")    }
elseif ($osName.Contains("Server 2003"))    {    $currentOS = "$osName"    $expectedVersion = New-Object System.Version("5.2.3790.6021")    }
else    {   $hotfixinfo+="Unable to determine OS applicability, please verify vulnerability state manually."    $currentOS = "$osName"    $expectedVersion = New-Object System.Version("9.9.9999.99999")    }
#Write-Host "`n`nCurrent OS: $currentOS (Build Number $($os.BuildNumber))" -ForegroundColor Cyan
#Write-Host "`nExpected Version of srv.sys: $($expectedVersion.ToString())" -ForegroundColor Cyan
#Write-Host "`nActual Version of srv.sys: $($fileVersion.ToString())" -ForegroundColor Cyan
If ($($fileVersion.CompareTo($expectedVersion)) -lt 0)    {    $hotfixinfo+= "`n`n"    $hotfixinfo+= "System is NOT Patched"     }
Else    {    $hotfixinfo+= "`n`n"    $hotfixinfo+= "System is Patched"    }
$outputarray=@()
$outputarray+=$hotfixinfo
$outputarray+=$cbout 
$outputarray+=$text
$outputarray -join ';'
'@
 $obj = foreach($vm in (Get-VM |  Where-Object {$_.PowerState -eq "Poweredon" -and $_.ExtensionData.Config.GuestFullName -like "*Microsoft*"})) {
 $out1 = Invoke-VMScript -VM $vm.Name -GuestUser "administrator" -GuestPassword "" -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput     
 New-Object PSObject -Property (    [ordered]@{        Name   = $vm.Name        OS     = $vm.Guest.OSFullName        IP     = ($vm.Guest.IPAddress | Where {($_.Split(".")).length -eq 4}) -join (",")        Cluster=$vm.VMHost.Parent.Name        RP     = $vm.ResourcePool.Name        Out1   = $out1  })
} 
$obj 
#|Export-Csv -Path 'C:\My Data\CSV Output\report.csv' -NoTypeInformation -NoClobber

Filter options like Where { $_.Created

$
0
0

Hi guys,

 

This filtering option, where can i find it other properties?

 

Found this in Get-VM|Get-Snapshot|Where{$_.Created-lt(Get-Date).AddDays(-7)}|Remove-Snapshot

 

from the command above i understood about what it will do but what i'm looking for and try to understand is the filter object $_.Created, i assumed it has other option as well than $_.Created which i wanted to understand due the nature of the filter object is not something you could enter tab button as like commandlet where it will assist you options of the syntax(i think).

 

 

 

 

Get HBA firmware and driver version for all ESXi hosts

$
0
0

Hello, as you probably know the only way to find out about HBA firmware and driver versions these days is by running:

 

/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -d     to see which are the HBA devices, then

/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -l -i vmhba1/qlogic     to actually retrieve the needed  info for a hba. In this particular case I get this precious data below:

 

value:

QLogic PCI to Fibre Channel Host Adapter for QMH2562:

        FC Firmware version 8.02.00 (90d5), Driver version 2.1.50.0

 

which I need to retrieve from all my ESXi and save to a file. I enjoy writing simple powercli scripts but I'm puzzled about this one. I know that esxcli commands can be scripted too but what about this? I could script something with plink

 

 

$plink = plink path

$plinkAuth=" -v -pw $Pswd"

$remoteCommand='/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -l -i vmhba1/qlogic'

$command="Echo Yes| "+$plink+" "+$plinkAuth+" "+$User+"@"+$hostName+" "+$remoteCommand

$result=Invoke-Expression-command$command

$result

 

but as the command above throws quite some stuff I don´t know how to grab only the data output I need and save it. Obviously this is to compare with vmware compatibility matrix later. Anyone did this? I already checked Re: Host Hardware info with HBA and nic driver information but the following values are returned blank, and not sure those match the  ones above that I need. I already added  the -V2 switch to the script of that post.

 

 

Fnicvendor   :

fnicdriver   :

enicdriver   :

Enicvendor   :

How to force users to choose only from a list of hosts, datastores, VLANs, etc

$
0
0

So it seems I'm never done with this script.  I want there to be default answers in some areas, and if a user passes something that's invalid it asks again until they pass a proper bit of info.

 

$type = Read-Host "Enter Host or Cluster"

if ($type -eq "Cluster")

{

Get-Cluster | Select Name | sort Name | Format-List #Gets a list of clusters in the vCenter#

$Cluster = Read-Host "Enter Cluster Name"

$myCluster = Get-Cluster -Name "$Cluster"

Get-VMHost -Location "$myCluster" -state "Connected" | sort Name | Select Name,ConnectionState,PowerState | Format-Table #Lists the host from the cluster specified earlier#

}

else

{

Get-VMHost | where {$_.state -eq "Connected"} | sort Name | Select Name,ConnectionState,PowerState | Format-Table

}

$vmHost = Read-Host "Enter host name"

Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS"} | Select @{N="Cluster";E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} | Out-Default #Lists datastores and capacity#

$datastore = Read-Host "Enter Datastore Name"

$myDatastore = Get-DataStore -Name "$datastore"

$ovfhost = Read-Host "Enter path to OVA/OVF"

$vmName = Read-Host "Enter a name for the VM"

$diskStorage = Read-Host "Enter Thin, Thick or EagerZeroedThick for disk format"

Import-vApp -Source "$ovfhost" -VMHost $vmHost -Location $myCluster -Name "$vmName" -DiskStorageFormat $diskStorage -Datastore $myDatastore #Imports the OVA/OVF into vCenter#

Sleep 10

$VMmove = Read-Host "Enter folder to move VM to"

Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate folder#

Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-Object {$strClusterName = $_.Parent.Name; Get-VirtualPortGroup $_ | Select-Object @{N="Cluster";E={$strClusterName}},Name,VLanId} #Gets available VLANs from the host#

$VLAN = Read-Host "Please enter the VLAN name to use"

$NIC = Get-NetworkAdapter -VM $vmName

 

So for the first part for $type it defaults to Host which I'm fine with.  After that I get a list of only hosts that are in the Connected state.  I'd like it if someone could just only type a name from the list provided, and if they don't provide one it prompts again.  Same thing would be fore the rest really, for the datastore, disk storage, folder path (hoping they put in a valid path) and VLAN type.  I'm new to all of this and have been googling around, just haven't found what I need yet.

Get the host name from rescan command

$
0
0

Hi,

 

Please help me to get the host name from below rescan command.

 

Command : Get-Cluster MyCluster | Get-VMHost | Get-VMHostStorage -RescanAllHba

 

Output :

 

SoftwareIScsiEnabled

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

False

False

False

False

powercli script to get used space, free space and % free of given datastores

$
0
0

hi can you provide a script to get used space, free space and % free space of selected datastores (name can be given).

I only need details of two of my 120 datastores.


Get Path Selection Policy Info

$
0
0

Hi,

 

I am unable to get the Path Selection Policy from the below script, please help

 

Get-Datastore | Select Name, Datacenter,

@{N="CapacityInGB";E={[math]::round($_.CapacityGB)}},

@{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) }},

@{N="FreeSpaceInGB";E={[math]::round($_.FreeSpaceGB)}},

@{N="VM Count";E={$_.ExtensionData.VM.Count}},

@{N='Vendor';E={(Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor}},

@{N="CanonicalName";E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}},

@{N="LUN";E={

             $esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

             $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

             $esxcli = Get-EsxCli -VMHost $esx.Name -V2

             $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')}},

@{N='PathPolicy';E={(Get-EsxCli -VMHost $vm.VMHost).storage.nmp.device.list($_.Info.Vmfs.Extent[0].DiskName) | Select -ExpandProperty PathSelectionPolicy}}

Creating a Scheduled Task for a VM

$
0
0

Currently I know how to create a task for a VM for a scheduled  recurring nightly task through the Web client, but I can't seem to figure out a way to create a task via PowerCLI.  Hopefully I'm just missing something really obvious.

 

Ultimately what I'd like to do is be able to something like search for a VM using Get-VM -VM $vmname and pipe that to return any scheduled tasks that vm has and if it currently doesn't have one then I'd love to be able to set a new task. In the context of my current use case, just simply scheduling a nightly reboot.

 

Sorry if I'm just missing something obvious, I'm just starting to dive into PowerCLI and loving what I can do so far.

 

Thanks!

Configuring Orchestrated Restart via PowerCLI

$
0
0

Clearly this isn't possible using New-DRSRule as the 'KeepTogether' parameter is boolean which only allows for specifying an affinity or anti-affinity rule.

 

So is it even possible to define an Orchestrated Restart rule via PowerCLI?

 

If it is possible, how is it done?

write-host causing error

$
0
0

Not really sure how it went this way but all other write-host was able to show output as i expected but not from these lines

 

#Create report

#Write-Host "Creating Report" -ForegroundColor Red

Export-Csv -Path $reportName -NoTypeInformation -UseCulture

 

 

#Send results via email

#Write-Host "email the report" -ForegroundColor Cyan

Send-MailMessage -SmtpServer $smtpServer -Subject "$smtpSubject $(Get-Date -f dd_MM_yyyy)" -To $to -From $from -Attachments $reportName

 

 

#delete the old snapshot report

#Write-Host "delete report in the folder" -ForegroundColor Yellow

Get-ChildItem -Path $att -Filter .csv* | Remove-Item

 

 

Disconnect-VIServer -Server * -Confirm:$false -Force

 

i have to bracket it with # since it doesnt work like it should,

but here are errors i received

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=SYMC-INC..._Service_IEDC1}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=SYMC-FUL..._Service_IEDC1}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=ASAUpgra...eGB=2.3; User=}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=ASAUpgra...eGB=2.3; User=}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=pre-upgr...eGB=7.4; User=}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=PFSense2...AU\~RKrawiecki}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=PFSense2...AU\~RKrawiecki}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=about to...U\~KSutherland}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

 

Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not

match any of the parameters that take pipeline input.

At C:\Batch\Scripts\snapshots\VM_snapshot.ps1:82 char:1

+ Write-Host "Creating Report" -ForegroundColor Red

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (@{Name=pre cert...GB=10.7; User=}:PSObject) [Write-Host], ParameterBindingException

    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.WriteHostCommand

Who created the Snapshot

$
0
0

 

Any idea how I can relatemy Get-Snapshot information to the Get-VIEvent information to work out who created a snapshot ?

 

 

 

 

 

Thanks

 

 

 

 

 

Alan

 

 

Create a scheduled reboot task for 700 VM in vcenter

$
0
0

Hi,

my goal is to create a reboot vm task guest os on a weekly basis every sunday night in vcenter

i have roughly 700 VM and i need to add a reboot task in vcenter for each vm

how can i automate the task creation for all vm ?

as far as i know there is no cmdlet command yet available to create vm tasks

is it possible ? perhaps there is a way around cmdlets commands....

any help will be appreciated

thanks

boudjel

get-esxcli V2, esxcli.storage.vmfs.unmap, "does not contain a method named 'unmap'"

$
0
0

PSVersion                      6.0.2

VMware.PowerCLI        10.1.0.8403314

 

 

>$esxcli = Get-EsxCli -VMHost "host1" -V2

>$ds = Get-VMHost "host1" | Get-Datastore | select -first 1

>$esxcli.storage.vmfs.unmap("4000",$ds,$null)

Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliElementImpl] does not contain a method named 'unmap'.

At line:1 char:1

+ $esxcli.storage.vmfs.unmap("4000",$ds,$null)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo          : InvalidOperation: (unmap:String) [], RuntimeException

+ FullyQualifiedErrorId : MethodNotFound

 

Without -V2, it running no errors. Why?

 

LucD

 


Remediate Host Profile

$
0
0

Is there any way to invoke a host profile remediate on a vmhost via PowerCLI?

When I use Invoke-VMHostProfile on a newly installed host the profile is applied to the host but there are multiple issues still open until I remediate the host via the webclient.

PowerCLI 6.5.4
vCenter/ESXi 6.0u3

Module not loaded when using Jenkins

$
0
0

I am testing powercli with jenkins and I am getting the below error

 

[EnvInject] - Loading node environment variables.

Building in workspace C:\Program Files (x86)\Jenkins\workspace\mine

[mine] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Windows\TEMP\jenkins6451574485999889179.ps1'"

Import-Module : The specified module 'VMware.VimAutomation.Core' was not

loaded because no valid module file was found in any module directory.

At C:\Windows\TEMP\jenkins6451574485999889179.ps1:1 char:1

+ Import-Module "VMware.VimAutomation.Core"

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ResourceUnavailable: (VMware.VimAutomation.Core:

   String) [Import-Module], FileNotFoundException

    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm

   ands.ImportModuleCommand

 

connect-viserver : The term 'connect-viserver' is not recognized as the name

of a cmdlet, function, script file, or operable program. Check the spelling of

the name, or if a path was included, verify that the path is correct and try

again.

At C:\Windows\TEMP\jenkins6451574485999889179.ps1:2 char:1

+ connect-viserver $vc -User $user -Password $pass

+ ~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (connect-viserver:String) [], Co

   mmandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

 

get-vm : The Hyper-V role is not installed on the destination host. Add the

Hyper-V role on that host and then run this cmdlet again.

At C:\Windows\TEMP\jenkins6451574485999889179.ps1:3 char:1

+ get-vm

+ ~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VirtualizationOperat

   ionFailedException

    + FullyQualifiedErrorId : Microsoft.HyperV.PowerShell.Commands.GetVMComman

   d

The remote server returned an error: (406) Not Acceptable

$
0
0

Hi all,

 

I'm new with Cloud Director and PowerCLI and I would like connect my vCD to create some stuffs.  But when I try to connect my vCD, I receive the following error:

Connect-CisServer The remote server returned an error: (406) Not Acceptable.. vmware

 

Executed command :

Connect-CIsServer -server xyz.com

 

Any idea is welcome...

 

Thx

Powercli Multi Host portgroup tagging

$
0
0

Do to the nature of my job I deal with multiple individual esx hosts.  They are nt part of vcenter cluster.  The script below works....somewhat.....NTP section is fine.....It is the portgroup section....it will apply the tags to the first host portgroup..then red inks and gives me a time out error.....I have tried to pipe portgroup commands to a start-stop to delay the tagging but it didnt except....any help would be appreciated.  This script is in first draft phase and I am just trying to get portgroups to tag on multiple hosts with exact same configuration.

 

 

 

# # # # # # # # # # # # # # # # # # # # # # # # # # # # #          

#                      Hello                            #  

#                                                       #

#     You will choose What Config you want to use       #

#                                                       #

# # # # # # # # # # # # # # # # # # # # # # # # # # # # #                                       

 

 

Write-Host -ForegroundColor DarkRed -BackgroundColor white "Welcome To Nutanix ESX Config Script"

 

 

# # # # # # # # # # # # # # # # #

#  Setting Variables for  Loop  #

# # # # # # # # # # # # # # # # #

 

 

$root = "root"

$pwd = "password"

$tag = "408"

$a = "x.x.x.x"

$b = "x.x.x.x"

$c= "x.x.x.x"

$esxlist = $a , $b , $c

$ntp1 = "x.x.x.x"

$ntp2 = "x.x.x.x"

$ntp3 = "x.x.x.x"

$ntp4 = "x.x.x.x"

######Begin Loop###########

foreach($esx in $esxlist) {

###########################

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "Choose a Configuration type Sir"

 

 

# # # # # # # # # # # # # # # # #

#  Setting Variable for Switch  #

# # # # # # # # # # # # # # # # #

 

 

$VmwareConfig = ""

 

 

Write-Host -ForegroundColor Green -BackgroundColor Black `

@"

1 = Configure NTP/Portgroup

2 = Configure NTP

3 = Configure Portgroup

"@; [int]$choicetype = Read-Host

 

 

switch ($choicetype) 

{

 

 

# # # # # # # # # # # # # # #

#   Configure NTP/Portgroup #

# # # # # # # # # # # # # # #

 

 

   1 {$VmwareConfig = `

 

 

Connect-VIServer -Server $esx -User $root -Password $pwd

 

 

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue

 

 

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "Please enter NTP Server Info"

 

 

###########Ensure Firewall Policy is Configured#####################################################################

Get-VMHostFirewallException -VMHost $esx | ? {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true

####################################################################################################################

 

 

######Add NTP Servers###########################################

Add-VMHostNtpServer -NtpServer $ntp1 , $ntp2 , $ntp3 , $ntp4 -VMHost $esx

################################################################

 

 

############Start NTP Service###############################################

Get-VmHostService -VMHost $esx | ?{$_.key -eq "ntpd"} | Start-VMHostService

############################################################################

 

 

#############Ensure service is set to start/stop on host#################################################

Get-VmHostService -VMHost $esx | ? {$_.key -eq "ntpd"} | Set-VMHostService -policy "on"

#########################################################################################################

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "NTP Config Complete, now lets configure the Portgroups to your desired specification"

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white " Tagging CVM Port Group"

 

 

#############Tagging CVM###################################################

Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "VM Network" | Set-VirtualPortGroup -VLanId $tag

###########################################################################

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "Tagging Host"

 

 

##########Tag Management Portgroup#################################################

Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "Management Network" | Set-VirtualPortGroup -VLanId $tag

###################################################################################

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "End Transmission"

 

 

}

     

 

 

# # # # # # # # # # # # #

#   Set NTP ServerS     #

# # # # # # # # # # # # #

  

   2 {$VmwareConfig = `  

  

######Begin Loop###########

foreach($esx in $esxlist) {

 

 

Connect-VIServer -Server $esx -User $root -Password $pwd

 

 

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue

 

 

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "Please enter NTP Server Info"

 

 

###########Ensure Firewall Policy is Configured#####################################################################

Get-VMHostFirewallException -VMHost $esx | ? {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true

####################################################################################################################

 

######Add NTP Servers###########################################

Add-VMHostNtpServer -NtpServer $ntp -VMHost $esx

################################################################

 

 

############Start NTP Service###############################################

Get-VmHostService -VMHost $esx | ?{$_.key -eq "ntpd"} | Start-VMHostService

############################################################################

 

 

#############Ensure service is set to start/stop on host#################################################

Get-VmHostService -VMHost $esx | ? {$_.key -eq "ntpd"} | Set-VMHostService -policy "on"

 

 

}

 

 

# # # # # # # # # # # # # # #

#   Configure Portgroups    #

# # # # # # # # # # # # # # #

 

 

   3 {$VmwareConfig = `

 

 

#########loggging into each host################

Connect-VIServer -Server $esx -User $root -Password $pwd

################################################

 

 

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue

 

 

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white " Tagging CVM Port Group"

 

 

#############Tagging CVM###################################################

Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "VM Network" | Set-VirtualPortGroup -VLanId $tag

###########################################################################

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "Tagging Host"

 

 

##########Tag Management Portgroup#################################################

Get-VirtualPortGroup -VirtualSwitch "vSwitch0" -Name "Management Network" | Set-VirtualPortGroup -VLanId $tag

 

 

###################################################################################

 

 

Write-Host -foregroundColor DarkGreen -BackgroundColor white "End Transmission"

     }

}

}

How to Convert NumCPU to An int?

$
0
0

i need to get the number of vCPUs on a VM and then cast the value into an integer data type.

 

$cpus = [int]( get-vm sqlvm1 | select NumCPU)

 

However it is telling me it can’t convert the data type of NumCPU to an int.

 

any ideas?

Viewing all 14549 articles
Browse latest View live