Search code examples
powershellsmb

Can't share Folder with Powershell


I'm trying to create a share on a Folder with Powersherll but it just won't work and I don't know why. I'm trying to share it with this comand:

New-SmbShare -Name "$($Username) Share" -Path "$($StandardPath)$($Username)\home\" -ChangeAccess "Labor\$($Username)"

But I always get this error:

New-SmbShare : The system cannot find the file specified. 
At C:\Users\ewzadmin\Desktop\AddADUsers.ps1:55 char:9
+         New-SmbShare -Name "$($Username) Share" -Path "$($StandardPat ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare) [New-SmbShare], CimException
    + FullyQualifiedErrorId : Windows System Error 2,New-SmbShare

I don't understand why he is trying to share a File when I want to share a Folder...


Solution

  • Okay I did find the Problem in my Script. It was that I was already using a \\192.168.1.32\users\$username\ path to create the folder. But because I didn't have a share the folder was never created...

    Im so dump