Powershell Script to create IIS director runs sucessfully on ISE but when I put it in my PHP code it does not run.


hello,

i hope can me.  i trying learn powershell , have hit dead end.  i have 3 items creating.

1.  welcome.php page

2.  input.html page

3.  powershell script iis.ps1.

if run powershell script on ise works fine.  it creates iis virtual directory me , physical directory.  but when use php 

<html>
<body>
<?php $psscriptpath = "c:\\iis.ps1";?>
<?php $query=shell_exec('c:\windows\system32\windowspowershell\v1.0\powershell.exe -noprofile -noninteractive -command ".c:\iis.ps1');?>
</body>
</html>

it not anything.  my script listed below


set-strictmode -version 2.0

$site="default web site"

write-host ""
write-host "                                                            " -backgroundcolor darkcyan
write-host "            iis setup script                                " -backgroundcolor darkcyan
write-host "       create virtual directories                           " -backgroundcolor darkcyan
write-host "                                                            " -backgroundcolor darkcyan
write-host ""
 
import-module webadministration -erroraction silentlycontinue
 
if (dir iis:\sites\$site) {write-host "checking $site configuration"}else{
write-error "$site not exist, exiting"
exit
}
write-host ""
 
# read existing values
#$rootpath = get-itemproperty ("iis:\sites\$site") -name physicalpath
$rootpath = "c:\inetpub\wwwroot\datix"
echo $rootpath
$pool = get-itemproperty ("iis:\sites\$site") -name applicationpool
 
# create new app
$virdir = "newapp"
 
if (dir iis:\sites\$site\$virdir -erroraction silentlycontinue)
{
 write-host "$site/$virdir/ virtual directory configured"}
else
{
 # create physical path if not present
 $apppath = join-path $rootpath $virdir
 $copypath = "c:\copy\*.*"
 echo $apppath
 if (!(test-path $apppath))
 { new-item -path $apppath -itemtype directory 
   echo $apppath
   copy-item $copypath $apppath }
 write-host "$site/$virdir/ virtual directory not configured, creating..."
 
 # create new iis application
 new-item iis:\sites\$site\$virdir -physicalpath "$rootpath\$virdir" -type application | out-null
 
 # set application pool
 set-itemproperty iis:\sites\$site\$virdir -name applicationpool -value $pool
 
 # create images virtual directory
 new-item iis:\sites\$site\$virdir\images -physicalpath "$rootpath\images" -type virtualdirectory
 
 write-host "created $site/$virdir/ virtual directory"
}


sumeet

php cannot run powershell scripts in files webs cannot read local system outside of virtual directory.

also run file this:

powershell -file .\file.ps1

you not able create under iis.


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...