Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Sharing problems with $ExecutionContext.InvokeCommand.NewScriptBlock

$
0
0

Hello.

I realy hope someone can help me here. I´m trying to create a folder on a remote server and then share this folder. The folder is created but it doesn´t get shared. I always get this error message:

The syntax of this command is:
    + CategoryInfo          : NotSpecified: (The syntax of this command is::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName      :
Myserver.domain.com
NotSpecified: (:) [], RemoteException
NET SHARE
sharename
          sharename=drive:path [/GRANT:user,[READ | CHANGE | FULL]]
                               [/USERS:number | /UNLIMITED]
                               [/REMARK:"text"]
                               [/CACHE:Manual | Documents| Programs | BranchCache | None]
          sharename [/USERS:number | /UNLIMITED]
                    [/REMARK:"text"]
                    [/CACHE:Manual | Documents | Programs | BranchCache | None]
          {sharename | devicename | drive:path} /DELETE
          sharename \\computername /DELETE

 

This is my script: (when i run the NET SHARE-command localy on the server the share works):

# Credentials
    $username = "domain\user"
    $pass = convertto-securestring -String "MyPassword" -AsPlainText -Force
    $cred = new-object -typename System.Management.Automation.PSCredential `
         -argumentlist $username, $pass

# Create DIR and Share-commands
    $CreateDir = $ExecutionContext.InvokeCommand.NewScriptBlock("mkdir F:\test\user")
    $CreateShare = $ExecutionContext.InvokeCommand.NewScriptBlock("NET SHARE user=F:\test\user /GRANT:everyone,FULL")


# Run them
    Invoke-Command -ComputerName "Myserver.domain.com" -ScriptBlock $CreateDir -Credential $cred
    Invoke-Command -ComputerName "Myserver.domain.com" -ScriptBlock $CreateChare -Credential $cred

 

I hope someone can help!


Viewing all articles
Browse latest Browse all 6937

Trending Articles