PHP and Powershell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good morning everyone,
  First time posting in here, although I've been listening in for a few weeks now.
So this one has got me stumped, I am fairly new to PHP but I cannot seem to Google through this one.
I cannot figure out how to 'exclude' PSComputerName and RunspaceId, which is ultimately what I'm struggling with. Please see below for script snips and explanations.

Also if there are any best practices you would recommend I'm open to it being that I am fairly new and self-taught to PHP scripting.


I have a bit of code I've put together (as ugly as it is) as follows in line:
<?php


###############
## Variables ##
###############

$TargetName = "Target1";
$login = "\$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @('administrator@xxxxxxxxxx',(ConvertTo-SecureString -String 'MyPassword' -AsPlainText -Force))";
$command = "Invoke-Command -computername 127.0.0.1 -credential \$cred -scriptblock {& Get-IscsiServerTarget -TargetName " . $TargetName . " | % { \$_.TargetIqn, \$_.Status}} -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)";
$psCMD = "powershell -ExecutionPolicy Unrestricted -command \"$login; $command\" <NUL";


########################################
## Variable Checking (For Debug Mode) ##
########################################

#echo "\$psCMD = $psCMD";


################
## Run Script ##
################

exec($psCMD,$out);


############
## Output ##
############

echo ('<pre>');
print_r($out);
echo ('</pre>');


###################
## End Of Script ##
###################

echo "End Of Scene";

?>

The issue I have is that it feeds back:

Array
(
    [0] => iqn.2013-04.com.widget:Target1
    [1] =>
    [2] => PSComputerName             RunspaceId                 Value
    [3] => --------------             ----------                 -----
    [4] => 127.0.0.1                  52fb8b1b-8d8b-4eec-9419... NotConnected
    [5] =>
    [6] =>
)

End Of Scene

What I should see so I can then turn it into variables is what I run when I run the command straight through the local Powershell command prompt which would return:
PS C:\Users\administrator.WIDGET.000> Get-IscsiServerTarget | % { $_.TargetIqn, $_.Status}
iqn.2013-04.com.widget:Target1
NotConnected
iqn.2013-04.com.widget:Target2
NotConnected
iqn.2013-04.com.widget:Target3
NotConnected
iqn.2013-04.com.widget:Target4
Connected
iqn.2013-04.com.widget:Target5
NotConnected
iqn.2013-04.com.widget:Target6
NotConnected

I cannot figure out how to 'exclude' PSComputerName and RunspaceId

Sorry in advance for the wordy explanation.

Cheers!

Alan


Please make note of my new email address: Alan.Loos@xxxxxxxxx.

CONFIDENTIALITY NOTICE: This e-mail and the attachment(s) hereto (if any) contain confidential information that is privileged and intended only for the addressee(s) hereof. If you are not an intended recipient, you are hereby notified that any disclosure, copying, distribution or use of this e-mail and/or the accompanying attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by return e-mail.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux