PerenniallyReserved with PowerCli

Hi Admins

Found this script in the forum which I think might solve some problems for me.

Assistance with the scrip value perpetually bulk bookings using Get-ESXCLi

$vmName = "VMwithRDM"

$vm = Get-VM -Name $vmName
$rdm = Get-HardDisk -DiskType rawPhysical -Vm $vm
$vmhosts = Get-Cluster -VM $vm | Get-VMHost
foreach ($esx in $vmhosts){
$esxcli = Get-EsxCli -VMHost $esx
Get - hard drive -DiskType rawPhysical -Vm $vm | %{
$esxcli . storage . kernel . device . list ($rdm. ScsiCanonicalName ) |
Select @{N="Time"; E={"{0:g}" -f (Get-Date). TimeOfDay {{ }},Device,IsPerenniallyReserved

$esxcli . storage . kernel . device . setconfig ($false,$rdm. ScsiCanonicalName , $true )

$esxcli . storage . kernel . device . list ($rdm. ScsiCanonicalName ) |
Select @{N="Time"; E={"{0:g}" -f (Get-Date). TimeOfDay {{ }},Device,IsPerenniallyReserved
}
}


But when I try to run this script, I get an error like:


Message: A specified parameter was not correct: argument [0];

InnerText: argument [0]

Online: 9.5 tank

+ $esxcli.storage.core.device.list($rdm.) ScsiCanonicalName) |

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

+ CategoryInfo: OperationStopped: (:)) [], InvalidArgument)

+ FullyQualifiedErrorId: VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument

Advice?


See you soon

Tyler



Try like this, it uses the variable of pipeline, in other words, the ROW coming out of the cmdlet Get-hard drive.

$vmName = "VMwithRDM".

$vm = get-VM-name $vmName

$vmhosts = get-Cluster - $vm VM | Get-VMHost

{foreach ($esx to $vmhosts)

$esxcli = get-EsxCli - VMHost $esx

Get-hard drive - DiskType rawPhysical - Vm $vm | %{

$esxcli.storage.core.device.list ($_.) ScsiCanonicalName) |

Select @{N = "Time"; E = {'{0:g}' f (Get-Date).} TimeOfDay}}, device, IsPerenniallyReserved

$esxcli.storage.core.device.setconfig ($false, $_.) ScsiCanonicalName, $true)

$esxcli.storage.core.device.list ($_.) ScsiCanonicalName) |

Select @{N = "Time"; E = {'{0:g}' f (Get-Date).} TimeOfDay}}, device, IsPerenniallyReserved

}

}

Tags: VMware

Similar Questions

  • How can I get the version of VMware to virtual machines with powercli officer?

    How can I get the version of VMware View Agent running on a virtual machine with powercli or view Powercli?

    As much as I know there is no cmdlet PowerCLI for this, but you can use the Invoke-VMScript cmdlet and interrogate the Win32_Product class.

    By running the following. You can add a Where clause to return only the Agent of the view

    Get-WmiObject-class Win32_Product | Select the name, Version

  • count the number of targets, devices and paths by hba for each host with powercli 5.5

    Hi all

    I'm writing this Question again in the community, was not able to found the answer I was looking for in the nets:

    https://communities.VMware.com/thread/516226?start=0 & tstart = 0

    https://communities.VMware.com/thread/293531

    I went through the scripts provided in the community, but seems that t not work on powercli 5.5.

    ///

    # The target account, devices and paths for each host

    Get-Cluster $cluster | Get-VMHost | Sort-Object-property name. {ForEach-Object

    $VMHost = $_

    $VMHost | Get-VMHostHba-type FibreChannel | Sort-Object-property device | {ForEach-Object

    $VMHostHba = $_

    $ScsiLun = $VMHostHba | Get-ScsiLun

    If {($ScsiLun)

    $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | `

    Where-Object {$_.} Name - like "$($VMHostHba.Device) *"} ".

    $Targets = ($ScsiLunPath |) »

    Group-object - property SanID | Measure - Object). County

    $Devices = ($ScsiLun |) Measure - Object). County

    $Paths = ($ScsiLunPath |) Measure - Object). County

    }

    Else {}

    $Targets = 0

    $Devices = 0

    $Paths = 0

    }

    $Report = "" | Select-Object - property VMHost, HBA, target devices, paths

    $Report.VMHost = $VMHost.Name

    $Report.HBA = $VMHostHba.Device

    $Report.Targets = $Targets

    $Report.Devices = $Devices

    $Report.Paths = $Paths

    $Report

    }

    }

    ///

    I went through the script LucD posted below: but it's not exactly what I'm looking for.

    LucD : can you please change the same for me please.   to count the number of paths per hba for each host with powercli 5.5, devices and targets.

    //

    $esx = get-VMHost < host name >

    foreach ($hba to (VMHostHba Get - VMHost $esx - type "FibreChannel")) {}

    $target = ((get - see $hba. VMhost). Config.StorageDevice.ScsiTopology.Adapter | where {$_.} Adapter - eq $hba. Key}). Goal

    $luns = get-ScsiLun - Hba $hba - LunType 'disk '.

    $nrPaths = ($target | % {$_.}) Lun.Count} | Measure - Object - sum). Sum

    Write-Host $hba. Device ' target: ' $target. County "devices:" $luns. County ' path: ' $nrPaths

    }

    //

    I'll be grateful for any help.

    Tarun Gupta

    Try something like this

    {foreach ($esx in Get-VMHost)

    foreach ($hba to (VMHostHba Get - VMHost $esx - type "FibreChannel")) {}

    $target = ((get - see $hba. VMhost). Config.StorageDevice.ScsiTopology.Adapter | where {$_.} Adapter - eq $hba. Key}). Goal

    $luns = get-ScsiLun - Hba $hba - LunType "disk" - ErrorAction SilentlyContinue

    $nrPaths = ($target | % {$_.}) Lun.Count} | Measure - Object - sum). Sum

    $props [ordered] = @ {}

    VMHost = $esx.name

    HBA = $hba. Name

    Target = $target. County

    Device = $luns. County

    Path = $nrPaths

    }

    New-object PSObject-property $props

    }

    }

  • Unable to connect to vCD with PowerCLI

    Hi, can you help me with troubleshooting problem with connecting in vCD using PowerCLI.

    When I log in using my system administrator account

    Connect-CIServer vcdCell01 - User "username-password"pass"

    I get:

    Connect-CIServer: 11/30/2015 connect 12:19:21 AM-CIServer the

    Server returned "Unauthorized" with the status of the authorized 401 - no code.

    On line: 1 char: 1

    + Connect CIServer vcdCell01 - User "username-password 'pass' '.

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

    + CategoryInfo: NotSpecified: (:)) [connect-CIServer], CIException)

    + FullyQualifiedErrorId: Cloud_ConnectivityServiceImpl_ConnectCloudServer

    _ConnectError, VMware.VimAutomation.Cloud.Commands.cmdlets.ConnectCIServer

    I can connect to the Web user interface using the same system administrator account.

    The only way I can connect with PowerCLI is when I create the local account in one of the organizations and Add - Org to order

    Connect-CIServer vcdCell01-user "localuser" - password 'localpass' - 'org' Org

    Help, please.

    I used a few tricks of Python to connect to vCD. To connect as a system administrator, I had to use "Administrator@System" as the user.

    Maybe it will work for you if you use '-Org system?

  • Download the virtual machine in a store of data with powercli

    Hello

    How to list the files of virtual machine on a store of data with PowerCLI

    I have a virtual machine and I want to see all the files in a data store (such as hard,.-flst.vmdk, .log, .nvram) using powercli. Is this possible?

    TKS.

    Try the following, it uses a function of my position of friendly units .

    Function Get-FriendlyUnit {}

    <>

    . Numbers converted small binary multiples SYNOPSIS

    . DESCRIPTION the function accepts a value and him will convert

    in the largest available binary unit.

    . Author NOTES: Luc relaxing

    . Value of the PARAMETER

    The value to convert.

    This number must be positive.

    . IEC PARAMETER

    A switch to indicate whether the function should return the CIS

    Unit, or the names of the units most commonly used names.

    The default is to use the commonly used unit names.

    . EXAMPLE OF

    PS > Get-FriendlyUnit-value 123456

    . EXAMPLE OF

    PS > 123456 | Get-FriendlyUnit - CIS

    . EXAMPLE OF

    PS > Get-FriendlyUnit-value 123456,789123, 45678

    #>

    (param

    [CmdletBinding()]

    [parameter (mandatory = $true, ValueFromPipeline = $true)]

    [double []] $Value,.

    [switch] $IEC

    )

    Begin {}

    $OldUnits = "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB".

    $IecUnits = 'B', 'KiB', 'MiB', "GiB", "TiB", "PIF", "BANK", "ZiB", "YiB".

    If ($IEC) {$units = $IecUnits} else {$units = $OldUnits}

    }

    {in process

    $Value | %{

    If ($_ - lt 0) {}

    Write-Error "Numbers must be positive."

    breaking

    }

    If ($value - gt 0) {}

    $modifier = [math]: Floor([Math]::Log($_,1KB)))

    }

    else {}

    $modifier = 0

    }

    New-object PSObject-property @ {}

    Value = $_ / [math]: Pow(1KB,$modifier)

    Unit = & {if ($modifier - lt $units. {Count) {$units [$modifier]} else {'1KO E {0}' f $modifier}}

    }

    }

    }

    }

    foreach ($vm in (Get-View - ViewType VirtualMachine - property Name, 'LayoutEx.File')) {}

    $vm. LayoutEx.File |

    Select @{N = "VM"; E = {$vm. Name}},

    @{N = 'Name'; E={$_. Name.Split(' ') [1]. "Split('/') [1]}},"

    @{N = "Path"; E={$_. Name}},

    @{N = 'FileType'; E={$_. Type}},

    @{N = "Datastore"; E={$_. Name.Split(']') [0]. TrimStart('[')}},

    @{N = "size"; E = {}

    $val = get-FriendlyUnit-value of $_. Size

    "{0:n2} {1}" f $val. Value, $val. Unit

    }}

    }

  • in bulk license with PowerCLI 6.0 Release 2 broken?

    Hello

    I upgraded successfully to PowerCLI 6.0 Release 1 to PowerCLI 6.0 Release 2.

    After that, I wanted to add a new license to the license in bulk newly deployed ESXi Hosts with Auto deploy but encountered the following error:

    $licenseData = new-Object VMware.VimAutomation.License.Types.LicenseData

    New-Object: cannot find type [VMware.VimAutomation.License.Types.LicenseData]: check that the assembly containing this type is loaded.

    On line: 1 char: 16

    + $licenseData = new-Object VMware.VimAutomation.License.Types.LicenseData

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

    + CategoryInfo: InvalidType: (:)) [New-Object], PSArgumentException)

    + FullyQualifiedErrorId: TypeNotFound, Microsoft.PowerShell.Commands.NewObjectCommand

    I'm sure that it worked with PowerCLI 6.0 Release 1.

    Did someone else run into it as well? Perhaps no work around?

    I appreciate your help.

    see you soon,

    Ronny

    Hello

    It is a backward compatibility problem that was introduced in PowerCLI 6.0R2. It will be addressed in a version of the next patch very soon, but until then, you can work around

    replacement of

    'VMware.VimAutomation.License.Types.LicenseData '.

    with

    'VMware.VimAutomation.License.Types.V1.LicenseData '.

    Keep in mind that if you do the above to make your script works and later upgrade your PowerCLI to a version more recent that you should check back this change in scripts.

    -Dimitar Milov

  • To connect to vCenter using the same Session with PowerCLI

    Hi all

    Is it possible that we can establish multiple connections to vCenter using the same session with Powercli.

    As connect-viserver-Server "vcenter1" - domain\domainacnt of the username-password "Password".

    is to establish several connections and we want to limit, because we are in the process of report generation based on the web developing using Powercli with IIS.

    Please suggest.

    You can use the Session parameter on the cmdlet Connect-VIServer .

    I use this for the PowerShell Workflows, see workflow of PowerShell and PowerCLI

  • I need a way to change the Login with PowerCLI 5.5 banner

    So I'm having a lot of problems with the fixing of the banner of connecting through Host Profiles.  It does not change the formatting at all, and it always shows not permitted even after the application.  Someone has found a way to define it with PowerCLI?  I saw ways to connect directly to the host ssh but I want to with a session PowerCLI, vCenter and does not direct connection to the host.  I would like to know if anyone has found anything!

    Thank you.

    We had a similar thread before, see script logon banner , but without using SSH, as I know there is no way to do it.

  • Moving a hard drive with PowerCLI

    I have a vm with several discs. I have create a new virtual machine, to attach a disk of the virtual machine first to this hard new using New-disk and passing the path to the vmdk.

    The final bit, that I need is to remove the disc from the first virtual machine so that I can turn on the second. I can't work out how to do this with powerCLI, of course, it is quite easy using the GUI.

    Any ideas?

    Hello, Deanb61-

    Decent docs: Yes, VMware support site has legitimate documentation: https://www.vmware.com/support/developer/PowerCLI/.  From there, you can see the documentation for the desired version of PowerCLI.  Of course, check the latest version the most up-to-date docs/features/etc.  Particular, Get-disk hard Ref is currently at http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.powercli.cmdletref.doc/Get-HardDisk.html.

    You can find the name of the hard disk on the original VM with the first bit below and use that name, then remove the disk said.  Or, the second line of code just relies on the way to the store of data (filename) from the drive and deletes the given virtual machine disk.

    ## get the VM's disks and their names, so as to use its name laterGet-HardDisk -VM myVM | select Name,Filename,CapacityGB
    
    ## or, just get the hard disk with the given filename, and remove itGet-HardDisk -VM myVM | Where-Object {$_.Filename -eq "[myDStore0] myVM/myVM1.vmdk"} | Remove-HardDisk -DeletePermanently:$false
    

    What to do for you?

  • How to get "Display Name" of RAW LUN with PowerCLI

    Hello

    I have a question:

    We have several RAW LUN and I changed the name to display in vCenter.

    How can I get all the changes in output in a CSV with PowerCLI?

    Thank you very much

    Try like this

    $esxName = "MyEsx."

    Get-VMHost-name $esxName | Get-ScsiLun - LunType disc |

    Select @{N = "DisplayName"; E={$_. ExtensionData.DisplayName}}, CanonicalName, RuntimeName

  • List of places scrape with powercli

    Hello

    I'm trying to script with powercli, but I'm not very good

    My goal is to list the location of the scratch for all my esx servers, and to link this information with the

    name of data store if possible. I want a file html with the following information:

    Get-VMHost-name * | Get-VMHostAdvancedConfiguration-name of the "ScratchConfig.ConfiguredScratchLocation".

    Get-VMHost-name * | Get-VMHostAdvancedConfiguration-name 'ScratchConfig.CurrentScratchLocation ' |

    ConvertTo-HTML | Out-file C:\myfile.html

    I don't see this script.

    If someone can help me...

    Thank you

    Try something like this

    $scratch="ScratchConfig.ConfiguredScratchLocation"&{foreach($esx in Get-VMHost){  Get-AdvancedSetting -Entity $esx -Name $scratch |  Select @{N="ESXi";E={$esx.Name}},Value}} | ConvertTo-Html | Out-File C:\report.html
    
    Invoke-Item c:\report.html
    
  • Information collection of operating system prompted with PowerCLI

    Can I get information about local groups inside with PowerCLI Windows operating system?

    No, this cmdlet and scripts invoked through it, do not depend on any configuration 'remote access' in the guest OS.

    In fact, the Invoke-VMScrpt cmdlet uses the VMware tools, which are a requirement, launch the script inside the guest OS.

    For the guest OS, it will look like a startup script locally.

    Make sure that the account under which the script is run, has the necessary permissions.

  • Vswitch group permissions management standard port with PowerCLI

    Hi all

    I have many groups of ports on standard as well as switches distributed on ESX 5.0.

    I would like to know if there is a way to manipulate the permissions of those groups of port with PowerCLI.

    Is it possible, or you can help automate this work?

    Thank you!

    The easiest are discussions on dvSwitches.

    For example

    $user = Get-VIAccount -Name "domain\lucd"$role = Get-VIRole -Name NetworkAdmin$dvPg = Get-VDPortgroup -Name "dvPortgroup"New-VIPermission -Principal $user -Role $role -Entity $dvPg
    

    The regular exchanges require the use of the API.

    For example

    $pgName = "VM Network"$pg = Get-VirtualPortGroup -Name "VM Network" | Select -First 1$net = Get-View (Get-View $pg.VMHostId).Network | where {$_.Name -eq $pgName}    $authMgr = Get-View AuthorizationManager$perm = New-Object VMware.Vim.Permission$perm.Principal = "domain\lucd"$perm.RoleId = $role.Id$perm.Propagate = $true$perm.Group = $false$authMgr.SetEntityPermissions($net.moref,$perm)
    

    Because the Get-VirtualPortgroup cmdlet does not have direct access to the corresponding object on the network , you have to find via the ESXi network property.

  • Average throughput of the network to a virtual machine with PowerCLI

    I would get average network throughput for a virtual machine with PowerCLI including all e-cards, the virtual machine has for the last week (not including NFS or storage of traffic-related).

    How best should add this report:

    Get - vm myvm | Select name, numcpu

    Thank you!

    Try like this

    Get-VM | Select Name, @{N="Avg Network Throughput MBPs";E={    [math]::Round((Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Stat "net.throughput.usage.average" |    where {$_.Instance -eq ""} |    Measure-Object -Property Value -Average | Select -ExpandProperty Average)/1KB,2)}}
    

    The script takes the aggregate value for all NICs for (the one where the Instance is an empty string).

    Then we take the average and converts the Kbps, Mbps.

  • Parameter of LVM. EnableResignature problem with PowerCLI vpshere 5.1 and 5.1 U2 Powercli

    Use us SRM and you want to make sure that when done with test that the LVM. EnableResignature is set to return 0 since move us hosts often. I tried 2 different ways to do it and they both fail with "a specified parameter was not correct", all examples I see online are for esx 4.x and below, I didn't know someone check this in 5.x.  We are 5.1U1 and latest powercli.

    Any help would be greatly appreciated.

    Method 1:

    $vh contains the name of the host to be reset:

    If ((Get-VMHostAdvancedConfiguration - vmhost $vh - name of LVM. EnableResignature). Values - not 0) {}

    Game-VMHostAdvancedConfiguration - vmhost $vh - name of LVM. EnableResignature-value 0 - confirm: $false

    }

    Method 2:

    Borrow the code for the functions I've seen online:

    If ((Get-VMHostAdvancedConfiguration - vmhost $vh - name of LVM. EnableResignature). Values - not 0) {}

    $esx = get-View (Get-VMHost $vh) USER.USER
    $optmgrMoRef = $esx.configManager.advancedOption
    $optmgr = get-views $optmgrMoRef

    $optarray = $optmgr. QueryOptions ("LVM. EnableResignature")
    $optarray [0]. Value = 0
    $optmgr. UpdateOptions ($optarray)

    }

    It seems as if the function of 9 Re: LVM/EnableResignature value = 1 with PowerCLI on ESX 4.1  

    work on 5.1 as well

    Function Set-VMHostResignature {}

    [CmdletBinding()]

    (Param

    [(Setting)

    Mandatory = $True,.

    ValueFromPipeline = $True

    )]

    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl []] $VMHost,.

    [(Setting)

    Mandatory = $True,.

    Position = 0

    )]

    [ValidateSet (0, 1)]

    [long] $Value

    )

    Begin {}

    $Option = new-Object Vmware.Vim .optionvalue - property @ {}

    Key = "LVM. EnableResignature ".

    Value = $Value

    }

    $OptionArray = $Option

    }

    {In process

    $VMHost | {ForEach-Object

    $ESX = get-view $_.ID

    $OptMgr = get - see $ESX. ConfigManager.AdvancedOption

    $OptMgr.UpdateOptions ($OptionArray)

    }

    }

    }

    Get-VMHost | Game-VMHostResignature-value 1

Maybe you are looking for