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:
$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!!