# Get-SmbShareAccess Cannot validate argument on parameter 'Name'

**URL:** <https://forums.powershell.org/t/get-smbshareaccess-cannot-validate-argument-on-parameter-name/16559>\
**Category:** PowerShell Help\
**Created:** [May 18, 2021, 5:13pm UTC](https://forums.powershell.org/t/get-smbshareaccess-cannot-validate-argument-on-parameter-name/16559 "2021-05-18T17:13:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![p.pasquali](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@p.pasquali](https://forums.powershell.org/u/p.pasquali)\
**Post date:** [May 18, 2021, 5:13pm UTC](https://forums.powershell.org/t/get-smbshareaccess-cannot-validate-argument-on-parameter-name/16559/1 "2021-05-18T17:13:44Z")

</div>

Hello, I apologize for the grammar, I use the Google translator.  
I’m a beginner with powershell, I’m trying to build a simple script to get the Share permissions of some shared folders. The script works fine if I don’t use a variable to indicate the folder.  
If I use the $ namefolder variable instead, it gives me an error.  
The script is:

```auto
$s = New-PsSession -ComputerName QTPSRV-01P
##Invoke-Command -Session $s {Get-SmbShare} | export-csv D:\Export\share.txt
$namefolder = 'share1'
$namefolder
Invoke-Command -Session $s {Get-SmbShareAccess $namefolder} ##| export-csv D:\Export\test1.txt

```

And the result is:

_Cannot validate argument on parameter ‘Name’. The argument is null. Provide a valid value for the argument, and then try running the command again._

- 
  - CategoryInfo : InvalidData: (🙂 [Get-SmbShareAccess], ParameterBindingValidationException\*

- 
  - FullyQualifiedErrorId : ParameterArgumentValidationError,Get-SmbShareAccess\*

- 
  - PSComputerName : QTPSRV-01P\*

How am I wrong to write the $ namefolder variable?  
Thank you very much!!

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [May 18, 2021, 5:16pm UTC](https://forums.powershell.org/t/get-smbshareaccess-cannot-validate-argument-on-parameter-name/16559/2 "2021-05-18T17:16:47Z")

</div>

variable `$namefolder` will not be accessible inside the scriptblock and in remote until explicitly passed. You can either use `$Using` prefix or Parameter blocks.

Using: `Invoke-Command -Session $S -ScriptBlock {Get-SMBShareAccess $Using:namefolder}`

Param block:

```auto
Invoke-Command -Session $S -ScriptBlock {
  Param($Share)
  Get-SMBShareAccess $Share
} -ArgumentList $namefolder

```

---

<div class="post-metadata">

**Author:** ![p.pasquali](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@p.pasquali](https://forums.powershell.org/u/p.pasquali)\
**Post date:** [May 19, 2021, 7:27am UTC](https://forums.powershell.org/t/get-smbshareaccess-cannot-validate-argument-on-parameter-name/16559/3 "2021-05-19T07:27:36Z")

</div>

Thank you very much kvprasoon, you made it clear to me why, now it works !!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:26pm UTC](https://forums.powershell.org/t/get-smbshareaccess-cannot-validate-argument-on-parameter-name/16559/4 "2024-05-16T20:26:24Z")

</div>

Closed on May 16, 2024, 8:26pm UTC


