locked
Some commands will not run in a single script file RRS feed

  • Question

  • Hi,

    To me this is an obscure problem. I have found some commands need to be 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 \\fs99\e$\users\TESTy9a1.McTestFace$ -itemType Directory

    Enter-PSSession -ComputerName fs99

    $cim1 = get-CimSession -ComputerName fs99

    new-smbshare -name "TESTy9a1.McTestFace$" -path e:\users\TESTy9a1.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, taking care NOT to close the remote session between running the scripts –

    Script1

    New-Item \\fs99\e$\users\TESTy9a1.McTestFace$ -itemType Directory

    Enter-PSSession -ComputerName fs99

    Script2

    $cim1 = get-CimSession -ComputerName fs99

    new-smbshare -name "TESTy9a1.McTestFace$" -path e:\users\TESTy9a1.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. So I’m missing something fundamental about the way these commands are queued or separated. Can you tell me what?

    Thanks!

    Pete

    Friday, May 25, 2018 5:14 PM

Answers

  • Possibly a question better asked on Powershell forum. This one is specific to the Data Science VM on Azure. 
    Wednesday, June 6, 2018 9:06 PM