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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With