3

I am creating a VBS in php that is being saved to a remote server on the network, I am then creating a powershell script to run it and executing from PHP.

$ITIMHOS = "ABD-DEF-123";    
//create the ps1
    $fs = fopen("\\\\spc-nsa-001\\nscap\\RunVBS.ps1","a"); //create batch file
    fwrite($fs,"Start-Process cmd.exe /c'\\\\spc-nsa-001\\nscap\\JP-Computer-import-".$ITIMHOS.".vbs'"); //write batch file contents
    fclose($fs);

the VBS has to be run on that remote server which is why I'm doing it this way, and it has to be run by a specific user and that's what i'm having trouble with. I currently use this:

 $psRun = '\\\\spc-nsa-001\\c$\\windows\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe'; //64bit server, 32bit web server
 $ps1File = '\\\\spc-nsa-001\\nscap\\runVBS.ps1';
exec($psRun.' -command '.$ps1File);

Can anyone advise/help with how I can run it with a different user (DOMAIN\user.name, P4$$word)

1 Answer 1

1

You can use Invoke-command or Enter-PSSession. Here is an example with Invoke-command

$computername = "remote computer"
$cred = Get-Credential
Invoke-Command -ComputerName $computername -Credential $cred -ScriptBlock {

    #command that you will run on remote system
}

Note that in order to use these cmdlet WinRM must be configured. Fore more details see here - https://technet.microsoft.com/en-us/library/hh849694.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.