我正在尝试使用Powershell脚本创建虚拟主机.它工作正常,但是我在编码方面遇到麻烦.我已经尝试了所有-encoding开关值,但没有运气.
这是我的剧本
$hostName = $args[0];
if ($args -eq $null -or $args.Length -eq 0)
{
"No arguments. Supply the virtual host name as the first argument."
exit
}
if (!(Test-Path -path D:\wamp\$hostName))
{
$indexText = "<?php echo `"<h1>Holder for $hostName</h1>`";"
New-Item D:\wamp\$hostName -type directory
New-Item D:\wamp\$hostName\index.php -type file
Out-File -FilePath D:\wamp\$hostName\index.php -InputObject $indexText -Encoding UTF8
}
$hosts = Get-Content C:\Windows\System32\drivers\etc\hosts
$hosts = $hosts + "127.0.0.1 $hostName.localhost"
Out-File -FilePath C:\Windows\System32\drivers\etc\hosts -InputObject $hosts
$conf = Get-Content "C:\Program Files (x86)\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf"
$conf = $conf + "<VirtualHost *:80>"
$conf = $conf + " DocumentRoot `"D:/wamp/$hostName`""
$conf = $conf + " ServerName $hostName.localhost"
$conf = $conf + " ErrorLog `"logs/$hostName.localhost-error.log`""
$conf = $conf + " CustomLog `"logs/$hostName.localhost-access.log`" common"
$conf = $conf + "</VirtualHost>"
Out-File -FilePath "C:\Program Files (x86)\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf" -InputObject $conf -Encoding ascii
Write-Host "Restart wamp server to effect changes"
有没有人设法使它可靠地工作,或者我是这里的入门者?我总是可以改用PHP