{"id":2017,"date":"2024-07-19T08:16:44","date_gmt":"2024-07-19T12:16:44","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=2017"},"modified":"2024-07-19T08:16:44","modified_gmt":"2024-07-19T12:16:44","slug":"powercli-get-tagassignment-and-inaccessibledatastore","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/powercli-get-tagassignment-and-inaccessibledatastore\/","title":{"rendered":"PowerCLI Get-TagAssignment and InaccessibleDatastore"},"content":{"rendered":"\n<p>I was recently speaking with a customer who mentioned an issue that occurred when using the PowerCLI <code>Get-TagAssignment<\/code> cmdlet.  They had a tag category which applied to clusters only.  If a host were offline or in maintenance mode, they were getting an error that a local datastore was not accessible.  I was able to recreate this issue and observed the following error text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-TagAssignment -Category h225-clusteronly-category\n\nTag                                      Entity\n---                                      ------\nh225-clusteronly-category\/h225-cluste... h206-cluster-storagepath\nGet-TagAssignment : 7\/14\/2024 10:30:04 AM       Get-TagAssignment               Datastore 'Local-h206-vesx-02' is not accessible. No\nconnected and accessible host is attached to this datastore.\nAt line:1 char:1\n+ Get-TagAssignment -Category h225-clusteronly-category\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    + CategoryInfo          : NotSpecified: (:) &#91;Get-TagAssignment], InaccessibleDatastore\n    + FullyQualifiedErrorId : Client20_TaggingServiceCisImpl_GetVDisks_Error,VMware.VimAutomation.ViCore.Cmdlets.Comma\n   nds.Tagging.GetTagAssignment\n<\/code><\/pre>\n\n\n\n<p>This is a peculiar error as the tag category only specifies ClusterComputeResource as an Associable Entity, so datastores should not be in scope and it is unexpected to see them called out in this context.  <\/p>\n\n\n\n<p>While looking into this error message, I stumbled across this blog post from a couple of years ago: <a href=\"https:\/\/virtuallyjason.blogspot.com\/2022\/02\/powercli-and-get-tagassignment.html\">https:\/\/virtuallyjason.blogspot.com\/2022\/02\/powercli-and-get-tagassignment.html<\/a>.  The article doesn&#8217;t touch specifically on this error message, but discuses performance related impact on specifying the <code>-Entity<\/code> parameter of the <code>Get-TagAssignment<\/code> cmdlet.  I did a bit of testing and confirmed that not only does specifying the entity improve performance, it also suppresses the error message that occurs for offline datastores.  <\/p>\n\n\n\n<p>To double check performance, I wanted run each command several times.  The loop below runs each command 100 times, then outputs the min, avg, and max run times for each command.  In my case, specifying <code>-Entity (Get-Cluster)<\/code> caused the execution to complete on average 5x quicker.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$myCommand = @()\n1..100 | %{\n  $myCommand += &#91;pscustomobject]&#91;ordered]@{\n    Iteration = $_\n    RunTime1 = (measure-command {Get-TagAssignment -Category h225-clusteronly-category}).TotalSeconds\n    RunTime2 = (measure-command {Get-TagAssignment -Category h225-clusteronly-category -Entity (Get-Cluster)}).TotalSeconds\n  }\n}\n\n$myCommand | Measure-Object -Property RunTime1 -Minimum -Average -Maximum \n$myCommand | Measure-Object -Property RunTime2 -Minimum -Average -Maximum <\/code><\/pre>\n\n\n\n<p>When using <code>Get-TagAssignment<\/code> there are a couple of good reasons to limit the scope of the cmdlet to only those entities required.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently speaking with a customer who mentioned an issue that occurred when using the PowerCLI Get-TagAssignment cmdlet. They had a tag category which applied to clusters only. If a host were offline or in maintenance mode, they were &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/powercli-get-tagassignment-and-inaccessibledatastore\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-2017","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=2017"}],"version-history":[{"count":2,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2017\/revisions"}],"predecessor-version":[{"id":2020,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2017\/revisions\/2020"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=2017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=2017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=2017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}