Application Integration
cancel
Showing results for 
Search instead for 
Did you mean: 

Powershell New-NSAccessControlRecord persistently fails

SOLVED
Go to solution
pmiller7
Occasional Visitor

Powershell New-NSAccessControlRecord persistently fails

I am attempting to script cloning a volume and connecting it to a test server. The cloning process works correctly, but assigning access to the test server persistently gives me an error as follows. 

$SAN='NimbleServerGroup.mycompany.net'  #my cluster is running Version  : 3.6.1.0

$mycred=Get-Credential -Message 'Nimble User and Password'

Connect-NSGroup -group $SAN -credential $mycred

$snapnm=(Get-NSSnapshotCollection | Where-Object name -like 'VolCollection-daily*' | sort name -Descending | select -First 1 )

$ss=($snapnm.snapshots_list | where {$_.Vol_name -eq 'VolumeName'})

New-NSClone -name 'CloneName' -base_snap_id $ss.ID -clone:$true -online:$true

$vol=(Get-NSVolume -Name 'CloneName')

$IG=(Get-NSInitiatorGroup -Name TestServer)

echo "Set Access for $($vol.name) on $($IG.name)"

New-NSAccessControlRecord -vol_id $vol.id -initiator_group_id $IG.iscsi_initiators.id -apply_to "both"

Server has not found the requested object.

Invoke-RestMethod : The remote server returned an error: (404) Not Found.

At C:\windows\system32\windowspowershell\v1.0\Modules\NimblePowerShellToolKit\NimblePowerShellToolKit.psm1:421 char:20

+         $restOut = Invoke-RestMethod -Uri $uri -Method $action -Body $body -Head ...

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

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Also if I specify some of the standard parms like -Verbose or -ErrorAction:Continue it fails with an error like:

     The request could not be understood by the server.Unexpected argument 'ErrorAction'.

Unfortunately the documentation for this command is very limited.  Can anyone suggest an alternate command or syntax that will work?

3 REPLIES
mblumberg16
Respected Contributor
Solution

Re: Powershell New-NSAccessControlRecord persistently fails

Hi Philip, the problem is with this value: -initiator_group_id $IG.iscsi_initiators.id

You're pulling the iscsi_initiators id and not the initiator group ID, what you need is  "-initiator_group_id $IG.id" in order to pull the initiator group id.

Example:

PS C:\Users\Administrator> Get-NSInitiatorGroup -name Hyper-Vhosts | select *

access_protocol  : iscsi

creation_time    : 23/02/2017 15:47:15

description      :

fc_initiators    :

full_name        : Hyper-Vhosts

id              : 02569e7fbad65b9423000000000000000000000071

iscsi_initiators : {@{id=0b569e7fbad65b94230000000000000000000000b8; initiator_id=0b569e7fbad65b94230000000000000000000000b8; label=emea-phy-win02; iqn=emea-phy-win02; ip_address=*}, @{id=0b569e7fbad65b94230000000000000000000000b9; initiator_id=0b569e7fbad65b94230000000000000000000000b9; label=emea-phy-win01; iqn=emea-phy-win01; ip_address=*}}

last_modified    : 23/02/2017 15:47:15

name            : Hyper-Vhosts

search_name      : Hyper-Vhosts

target_subnets  :

PS C:\Users\Administrator> Get-NSVolume  -name Windows2012r2CSV03 | select id

id

--

06569e7fbad65b942300000000000000000000005d

PS C:\Users\Administrator> New-NSAccessControlRecord -vol_id 06569e7fbad65b942300000000000000000000005d -initiator_group_id 0b569e7fbad65b94230000000000000000000000b8

Server has not found the requested object.

Invoke-RestMethod : The remote server returned an error: (404) Not Found.

At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NimblePowerShellToolkit\NimblePowerShellToolKit.psm1:421 char:20

+        $restOut = Invoke-RestMethod -Uri $uri -Method $action -Body $body -Head ...

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

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Correct:

PS C:\Users\Administrator> New-NSAccessControlRecord -vol_id 06569e7fbad65b942300000000000000000000005d -initiator_group_id 02569e7fbad65b9423000000000000000000000071

access_protocol      : iscsi

apply_to            : both

chap_user_id        :

chap_user_name      : *

creation_time        : 10/03/2017 10:12:41

id                  : 0d569e7fbad65b94230000000000000000000018dc

initiator_group_id  : 02569e7fbad65b9423000000000000000000000071

initiator_group_name : Hyper-Vhosts

last_modified        : 10/03/2017 10:12:41

lun                  : 0

pe_id                :

pe_lun              :

pe_name              :

snap_id              :

snap_name            :

snapluns            :

vol_id              : 06569e7fbad65b942300000000000000000000005d

vol_name            : Windows2012r2CSV03

pmiller7
Occasional Visitor

Re: Powershell New-NSAccessControlRecord persistently fails

Changing to "-initiator_group_id $IG.id" worked! I know I had tried that before, but I think I must have had something else wrong in the command and changed the wrong thing to in the attempt to correct the error.  Additional examples in the documentation would have been helpful.

 

Is there anything that can be done to correct the "unexpected argument" error if you specify other powershell parameters like "-Verbose" or "-ErrorAction"?

mblumberg16
Respected Contributor

Re: Powershell New-NSAccessControlRecord persistently fails

no worries, you want to try a try/catch

something like this:

This will continue the script even though there was an error.

try {

      $connection = New-NSAccessControlRecord -vol_id 06569e7fbad65b942300000000000000000000005d -initiator_group_id $vv.iscsi_initiators.id -errorAction Stop

    }

  catch

    {

        Write-Host "`nFailed to add acl."

    }

    Write-Host "starting next task"

    Get-NSInitiatorGroup -name SVCMM-server

output:

PS C:\Users\Administrator\Desktop> .\1.ps1

The request could not be understood by the server.Unexpected argument 'ErrorAction'.

.Failed to add acl

starting next task

name             : SVCMM-server

access_protocol  : iscsi

target_subnets   :

iscsi_initiators : {@{id=0b569e7fbad65b94230000000000000000000000b7; initiator_id=0b569e7fbad65b94230000000000000000000000b7; label=iqn.1991-05.com.microsoft:emea-vm-scvmm.nimblesupportlab.com; iqn=iqn.1991-05.com.microsoft:emea-vm-scvmm.nimblesupportlab.com; ip_address=*}}

fc_initiators    :

PS C:\Users\Administrator\Desktop>

If you want it to abort: add Exit :

try {

      $connection = New-NSAccessControlRecord -vol_id 06569e7fbad65b942300000000000000000000005d -initiator_group_id $vv.iscsi_initiators.id -errorAction Stop

    }

  catch

    {

        Write-Host "`nFailed to add acl."

        Exit

    }

    Write-Host "starting next task"

    Get-NSInitiatorGroup -name SVCMM-server



This will die after the failure.