Please help Out PSCX 3.0 MSI Install. What next?

Topics: Developer Forum, User Forum
Dec 4, 2012 at 2:30 PM
Edited Dec 4, 2012 at 3:34 PM

Hey guys,

BACKGROUND:

Windows 7 x64

Powershell 3.0 installed via: Windows6.1-KB2506143-x64.msu

PSCX 3.0 installed via: Pscx-3.0.0.msi

Policy: Set-ExecutionPolicy -ExecutionPolicy Bypass

QUERY:

How do I "activate" the PSCX 3.0 Commandlets?

Sample commands I run below lead me to believe PSCX Commandlets are not registered on the system.

 

 

SAMPLE COMMANDS I RUN:

help Get-ClipboardGet-Help

Get-Help could not find Get-Clipboard in a help file in thissession. To download updated help topics type: "Update-Help". To get helponline, search for the help topic in the TechNet library athttp://go.microsoft.com/fwlink/?LinkID=107116.At line:55 char:7+       Get-Help @PSBoundParameters | more+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : ResourceUnavailable: (:) [Get-Help], HelpNotFoun   dException    + FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHe   lpCommand

 

 .\Make-PS1ExeWrapper.ps1 .\Ingester.ps1 .\Ingester.exe .\Ingester.ico

Write-GZip The term 'Write-GZip' is not recognized as the name of a cmdlet,function, script file, or operable program. Check the spelling of the name, orif a path was included, verify that the path is correct and try again.At C:\ew\Make-PS1ExeWrapper.ps1:647 char:42+         $gzItem = Get-ChildItem $rpath | Write-GZip -Quiet+                                          ~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (Write-GZip:String) [], CommandN   otFoundException    + FullyQualifiedErrorId : CommandNotFoundException

Property 'Directory' cannot be found on this object. Make sure that it exists.At C:\ew\Make-PS1ExeWrapper.ps1:648 char:28+         $resourcePath = "$($gzItem.Directory)\Resources.Script.ps1.gz"+                            ~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException    + FullyQualifiedErrorId : PropertyNotFoundStrict
Rename-Item : Cannot bind argument to parameter 'Path' because it is null.At C:\ew\Make-PS1ExeWrapper.ps1:650 char:21+         Rename-Item $gzItem $resourcePath+                     ~~~~~~~    + CategoryInfo          : InvalidData: (:) [Rename-Item], ParameterBinding   ValidationException    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M   icrosoft.PowerShell.Commands.RenameItemCommand
C:\ew\Make-PS1ExeWrapper.ps1 :    244:    The type 'System.Dynamic.IDynamicMetaObjectProvider' is defined inan assembly that is not referenced. You must add a reference to assembly'System.Core, Version=4.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089'.At line:1 char:1+ .\Make-PS1ExeWrapper.ps1 .\Ingester.ps1 .\Ingester.exe .\Ingester.ico+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorExcep   tion    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio   n,Make-PS1ExeWrapper.ps1

Coordinator
Dec 4, 2012 at 4:46 PM

First, Make-PS1ExeWrapper is not part of PSCX (at least not yet).  Second, try setting the execution policy to RemoteSigned and run a simple command like Get-Uptime.

Dec 5, 2012 at 7:07 AM

Thanks for swift reply  r_keith_hill!

 

Here is the output of commands you proposed as test:

 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Execution Policy ChangeThe execution policy helps protect you from scripts that you do not trust.Changing the execution policy might expose you to the security risks describedin the about_Execution_Policies help topic athttp://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change theexecution policy?[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

Get-ExecutionPolicy

RemoteSigned

 

Get-Uptime

Get-Uptime : The term 'Get-Uptime' is not recognized as the name of a cmdlet,function, script file, or operable program. Check the spelling of the name, orif a path was included, verify that the path is correct and try again.At line:1 char:1+ Get-Uptime+ ~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (Get-Uptime:String) [], CommandN   otFoundException    + FullyQualifiedErrorId : CommandNotFoundException

 

I also verified that files from MSI extracted into: c:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\

 

 

 

Coordinator
Dec 5, 2012 at 4:07 PM

On some systems, I've seen a log off/log in required.  The installer sets an environment variable (PSModulePath) to add the PSCX install dir.  If that doesn't take effect immediately after the install, PowerShell can't find the PSCX module.  Until you get a chance to log off & back in you can load the module manually:

Import-Module 'c:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\pscx.psd1'

Dec 6, 2012 at 2:50 PM

Thank you very much it works now!

Having a different problem now posted below, but this is nothing to do with PSCX 3.0 MSI Install so dont worry about it unless you know of top of your head :)

 .\Make-PS1ExeWrapper.ps1 .\Ingester.ps1 .\Ingester.exe

Make-PS1ExeWrapper.ps1 :    244:    The type 'System.Dynamic.IDynamicMetaObjectProvider' is defined inan assembly that is not referenced. You must add a reference to assembly'System.Core, Version=4.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089'.At line:1 char:1+ .\Make-PS1ExeWrapper.ps1 .\Ingester.ps1 .\Ingester.exe+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorExcep   tion    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio   n,Make-PS1ExeWrapper.ps1

 

Coordinator
Dec 8, 2012 at 5:27 AM

Grab the Make-PS1ExeWrapperWithArgs from the same SkyDrive location and then use the -NET40 parameter.

Dec 13, 2012 at 12:55 PM

Thank you r_keith_hill just got a chance to come back to this project and your solution works!

( .\Make-PS1ExeWrapperWithArgs.ps1 -NET40 .\Ingester.ps1 .\Ingester.exe)

Dec 13, 2012 at 1:17 PM
Edited Dec 13, 2012 at 1:30 PM

Unfortunately the exe version does not like some code that works in Windows Powershell ISE :/

 

Below is only executed if I start the exe as Admin.

$temp | out-file C:\FMSTESTv2\temp.txt 

 

 

Then code runs then up to here:

#grep / awk (grep “somestring” C:\FMSTESTv2\temp.txt | awk ‘{print $1}’

$tempA = select-string -pattern “$fmsno” C:\FMSTESTv2\temp.txt | foreach { $_.ToString().split(",")[1] }

 

And issues start after this line:

You cannot call a method on a null-valued expression.

At line:23 char:1

+ $tempB = ($tempA).ToString().Replace("'" , "")

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

 

You cannot call a method on a null-valued expression.

At line:26 char:1

+ $tempC = $tempB.split("/")

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

 

Cannot index into a null array.

At line:29 char:1

+ $Ip = $tempC[0]

+ ~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : NullArray

Coordinator
Dec 13, 2012 at 4:05 PM

This line:

$tempA = select-string -pattern �$fmsno� C:\FMSTESTv2\temp.txt | foreach { $_.ToString().split(",")[1] }

Is not finding anything so $tempA is equal to $null.  Then you attempting to access a .NET method (.Split()) on a null value.  That's always going to crash.  So perhaps the select-string line should be finding something and it isn't or if it is possible it will find nothing, then you need to put in some null checks e.g.:

if ($tempA -ne $null) {
    $tempB = $tempA.ToString().Replace(...)
}
Dec 13, 2012 at 4:09 PM
Edited Dec 13, 2012 at 5:00 PM

Thanks for suggestions r_keith_hill

I will work on this more most likely.

Any idea why it works in Windows Powershell ISE? (C:\FMSTESTv2\temp.txt is accessed and the $tempA is assigned to a string)

Dec 14, 2012 at 1:18 PM

Dear  r_keith_hill thank you for all support :).

I managed to get the code working in ISE and compiled to an exe.

I had to redo the below:

$temp | out-file C:\FMSTESTv2\temp.txt  # because it needed the exe run as Admin

$tempA = select-string -pattern “$fmsno” C:\FMSTESTv2\temp.txt | foreach { $_.ToString().split(”,“)[1] } #because this would not work compiled even rus as Admin

So as long as the script runs on-the-fly everything is fine.