Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Windows Powershell | No Comment | 1,478 views | 14/07/2012 21:49
Your script needs “Run as Administrator” privileges? Then you should use this function to check it.
1
2
3
4
5
6
7
8
9
| function Confirm-PoSHAdminPrivileges
{
$User = [Security.Principal.WindowsIdentity]::GetCurrent()
if((New-Object Security.Principal.WindowsPrincipal $User).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
{
$Result = "Validated"
}
$Result
} |
function Confirm-PoSHAdminPrivileges
{
$User = [Security.Principal.WindowsIdentity]::GetCurrent()
if((New-Object Security.Principal.WindowsPrincipal $User).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
{
$Result = "Validated"
}
$Result
}
If you get “Validated” as a output, then you can be sure about administrator privileges.
Posted in Windows Powershell | No Comment | 7,575 views | 14/07/2012 21:45
If you install Parallels Plesk before, you should be aware about “Welcome Banner” of Plesk. It’s pretty cool! I did same thing on Powershell and made it function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| function Get-PoSHWelcomeBanner
{
param ($Hostname, $Port)
# Get Hostname
if (!$Hostname -or $Hostname -eq "+")
{
$Hostname = "localhost"
}
else
{
$Hostname = @($Hostname.Split(","))[0]
}
# Get Port
if ($Port -ne "80")
{
$Port = ":$Port"
}
clear
Write-Host " "
Write-Host " Welcome to PoSH Server"
Write-Host " "
Write-Host " "
Write-Host " You can start browsing your webpage from:"
Write-Host " http://$Hostname$Port"
Write-Host " "
Write-Host " "
Write-Host " Thanks for using PoSH Server.."
Write-Host " "
Write-Host " "
Write-Host " "
} |
function Get-PoSHWelcomeBanner
{
param ($Hostname, $Port)
# Get Hostname
if (!$Hostname -or $Hostname -eq "+")
{
$Hostname = "localhost"
}
else
{
$Hostname = @($Hostname.Split(","))[0]
}
# Get Port
if ($Port -ne "80")
{
$Port = ":$Port"
}
clear
Write-Host " "
Write-Host " Welcome to PoSH Server"
Write-Host " "
Write-Host " "
Write-Host " You can start browsing your webpage from:"
Write-Host " http://$Hostname$Port"
Write-Host " "
Write-Host " "
Write-Host " Thanks for using PoSH Server.."
Write-Host " "
Write-Host " "
Write-Host " "
}
Seriously, this looks good :) It’s a good way to redirect people to web browser.
Posted in Windows Powershell | No Comment | 3,321 views | 14/07/2012 21:39
I’ve recently added PHP support on PoSHServer. Here is my example codes for PHP execution on PowerShell:
Main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| $PHPCgiPath = "C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" # WebPI Location
$TestPHPCgiPath = Test-Path $PHPCgiPath
if ($TestPHPCgiPath)
{
$Response.ContentType = "text/html"
$PHPQuery = Get-PoSHPHPQuery -Request $Request
$PHPContentOutput = Get-PoSHPHPContent -File $File -QueryString $PHPQuery -PHPCgiPath $PHPCgiPath
$PHPContentOutput = Set-PHPEncoding -PHPOutput $PHPContentOutput
$Response.StatusCode = [System.Net.HttpStatusCode]::OK
$LogResponseStatus = $Response.StatusCode
$Response = New-Object IO.StreamWriter($Response.OutputStream,[Text.Encoding]::UTF8)
$Response.WriteLine("$PHPContentOutput")
}
else
{
$Response.ContentType = "text/html"
$Response.StatusCode = [System.Net.HttpStatusCode]::NotFound
$LogResponseStatus = $Response.StatusCode
$Response = New-Object IO.StreamWriter($Response.OutputStream,[Text.Encoding]::UTF8)
$Response.WriteLine("$(. $PoSHModulePath\modules\phpcgierror.ps1)")
} |
$PHPCgiPath = "C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" # WebPI Location
$TestPHPCgiPath = Test-Path $PHPCgiPath
if ($TestPHPCgiPath)
{
$Response.ContentType = "text/html"
$PHPQuery = Get-PoSHPHPQuery -Request $Request
$PHPContentOutput = Get-PoSHPHPContent -File $File -QueryString $PHPQuery -PHPCgiPath $PHPCgiPath
$PHPContentOutput = Set-PHPEncoding -PHPOutput $PHPContentOutput
$Response.StatusCode = [System.Net.HttpStatusCode]::OK
$LogResponseStatus = $Response.StatusCode
$Response = New-Object IO.StreamWriter($Response.OutputStream,[Text.Encoding]::UTF8)
$Response.WriteLine("$PHPContentOutput")
}
else
{
$Response.ContentType = "text/html"
$Response.StatusCode = [System.Net.HttpStatusCode]::NotFound
$LogResponseStatus = $Response.StatusCode
$Response = New-Object IO.StreamWriter($Response.OutputStream,[Text.Encoding]::UTF8)
$Response.WriteLine("$(. $PoSHModulePath\modules\phpcgierror.ps1)")
}
Function:
1
2
3
4
5
6
7
| function Get-PoSHPHPContent
{
param ($File, $QueryString, $PHPCgiPath)
$PHPOutput = &$PHPCgiPath -f $File $QueryString
$PHPOutput
} |
function Get-PoSHPHPContent
{
param ($File, $QueryString, $PHPCgiPath)
$PHPOutput = &$PHPCgiPath -f $File $QueryString
$PHPOutput
}
You can always download PoSHServer to see it live! :)
|