Commands that do not run in a single script

Home Forums Scripting PowerShell Commands that do not run in a single script

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    peterhala
    Member
    #167568

    Hi,

    To me this is an obscure problem. I have found some commands need to be separated/delayed or they do not execute. I have seen this when running commands on a remote system. For example the following script (run from a workstation against a local server) _almost_ creates a folder, shares it and then tweaks the share permissions

    New-Item \fs99e$usersTESTy9a1.McTestFace$ -itemType Directory

    Enter-PSSession -ComputerName fs99

    $cim1 = get-CimSession -ComputerName fs99

    new-smbshare -name “TESTy9a1.McTestFace$” -path e:usersTESTy9a1.McTestFace$ -CimSession $cim1

    grant-smbshareaccess TESTy9a1.McTestFace$ -accountname Everyone -accessright Full -CimSession $cim1 -Confirm:$false

    The script fails on the third line, saying smbshare is not a recognized command. If I split these commands into two files as follows, taking care NOT to close the remote session between running the scripts –

    Script1:

    New-Item \fs99e$usersTESTy9a1.McTestFace$ -itemType Directory

    Enter-PSSession -ComputerName fs99

    Script2:

    $cim1 = get-CimSession -ComputerName fs99

    new-smbshare -name “TESTy9a1.McTestFace$” -path e:usersTESTy9a1.McTestFace$ -CimSession $cim1

    grant-smbshareaccess TESTy9a1.McTestFace$ -accountname Everyone -accessright Full -CimSession $cim1 -Confirm:$false

    It works fine; the split means my smb commands ARE being run on the remote system. However I have not changed the commands or the order in which they are run. So I’m missing something fundamental about the way these commands are queued or separated. Can you tell me what?

    Thanks!

    Pete

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.