Re: PHP and Powershell
| From: | Serge Fonville | Date: | Mon, 22 Jul 2013 09:08:53 +0000 |
| Subject: | Re: PHP and Powershell | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-321669@lists.php.net to get a copy of this message | ||
Hi,
Thanks for your change.
I understand what has happend, from MSDN forums
http://social.technet.microsoft.com/Forums/windowsserver/en-US/4b841530-9d8c-4d09-a77c-b89c6e0bafab/how-do-i-capture-data-from-invokecommand
http://technet.microsoft.com/en-us/library/jj612804.aspx
describes that
Get-IscsiServerTarget returns an instance of
Microsoft.Iscsi.Target.Commands.IscsiServerTarget. De output also includes
the runspaceid and pscomputername. Invoke-Command also returns a runspaceid
(when executed with -computername).
You need to use Select-Object to output only the relevant fields instead.
HTH
Kind regards/met vriendelijke groet,
Serge Fonville
http://www.sergefonville.nl
Convince Microsoft!
They need to add TRUNCATE PARTITION in SQL Server
https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table
2013/7/19 Alan Loos <Alan.Loos@genco.com>
> Serge,
>
> I have, the script itself allows for easy transition into a .ps1, what I
> have done is removed the # from the debug section to get the full command
> that is then easily ‘copy and paste’-able into a Powershell prompt and I
> get the same response in Powershell directly.
>
> Also in response to the lastest post to the thread I will snip off some
> content here. (Sorry first time at this)
>
>
>
> The ultimate goal is to pull the two variables so I can pass them forward
> via a PHP script to a MySQL Database.
>
> (ie iqn.2013-04.com.widget:Target1 and NotConnected in this case)
>
>
>
> I believe that the command in Powershell is trying to gather the $Status
> on both the Invoke-Command and Get-iSCSIServerTarget commands. Which is why
> I am getting a table in the Powershell Console and browser.
>
>
>
> Per your request I have rewritten the scripts:
>
> (Included inline)
>
> TestGetServerTarget.php
> ------------------------------
>
> <?php
>
>
>
>
>
> ###############
>
> ## Variables ##
>
> ###############
>
>
>
> $psCMD = "powershell.exe -ExecutionPolicy Unrestricted";
>
> $psFILE = "C:\\Arc\\scripts\\TestGetTarget.ps1";
>
> $runCMD = $psCMD." ".$psFILE;
>
>
>
> ########################################
>
> ## Variable Checking (For Debug Mode) ##
>
> ########################################
>
>
>
> #echo "\$psCMD = $psCMD";
>
>
>
>
>
> ################
>
> ## Run Script ##
>
> ################
>
>
>
> exec($runCMD, $out);
>
>
>
>
>
> ############
>
> ## Output ##
>
> ############
>
>
>
> echo ('<pre>');
>
> print_r($out);
>
> echo ('</pre>');
>
>
>
>
>
> ###################
>
> ## End Of Script ##
>
> ###################
>
>
>
> echo "End Of Scene";
>
>
>
>
>
> ?>
> ------------------------------
>
>
>
>
>
> TestGetTarget.ps1
> ------------------------------
>
> ###############
>
> ## Variables ##
>
> ###############
>
>
>
> $cred = New-Object System.Management.Automation.PSCredential -ArgumentList
> @('administrator@widget.com',(ConvertTo-SecureString -String 'MyPassword'
> -AsPlainText -Force))
>
> $command = Invoke-Command -computername localhost -credential $cred
> -scriptblock {& Get-IscsiServerTarget -TargetName Target1 | % {
> $_.TargetIqn, $_.Status}} -SessionOption (New-PSSessionOption -SkipCACheck
> -SkipCNCheck -SkipRevocationCheck)
>
>
>
>
>
> #########################
>
> ## Execute Scriptblock ##
>
> #########################
>
>
>
> $command
> ------------------------------
>
>
>
> Powershell output of TestGetTarget.ps1:
> ------------------------------
>
> PS C:\Arc\Scripts> .\TestGetTarget.ps1
>
> iqn.2013-04.com.widget:Target1
>
>
>
> PSComputerName RunspaceId
> Value
>
> --------------
> ---------- -----
>
> localhost
> f3c5063a-85df-49a3-a5ed-7df04a930684 NotConnected
> ------------------------------
>
>
>
> PHP output webbrowser (Much in the same):
> ------------------------------
>
> Array
>
> (
>
> [0] => iqn.2013-04.com.widget:Target1
>
> [1] =>
>
> [2] => PSComputerName RunspaceId Value
>
> [3] => -------------- ---------- -----
>
> [4] => localhost f46c9f15-70b4-496c-a9d6...
> NotConnected
>
> [5] =>
>
> [6] =>
>
> )
>
>
>
> End Of Scene
> ------------------------------
>
>
>
>
>
> *Alan Loos*
>
>
>
> 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.
>
>
>
> *From:* Serge Fonville [mailto:serge.fonville@gmail.com]
> *Sent:* Friday, July 19, 2013 12:16 PM
>
> *To:* Alan Loos
> *Cc:* php-general@lists.php.net
> *Subject:* Re: [PHP] PHP and Powershell
>
>
>
> Thank you for your clarification.
>
>
> Have you considered placing the whole powershell -command parameter in a
> .ps1 script and executing that instead?
>
> The benefit would be that it is easier to read and test accordingly.
>
> HTH
>
> Kind regards/met vriendelijke groet,
>
>
>
> Serge Fonville
>
>
>
> http://www.sergefonville.nl
>
> Convince Microsoft!
>
> They need to add TRUNCATE PARTITION in SQL Server
>
>
>
> https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table
>
>
>
> --Big Snip--
>
> Please make note of my new email address: *Alan.Loos@genco.com*.
>