Author Topic: PowerShell Path Issue  (Read 490 times)

Jeremy Whilde

  • Jr. Member
  • **
  • Posts: 50
PowerShell Path Issue
« on: January 30, 2018, 02:05:40 am »
Does anyone know how to get around this PowerShell path issue?

I am trying to run Get_Item Property on a dll in windows\system32 folder, which works if I manually enter the string shown below but when run from WB seems to fail with the Cannot find path error.

DirChange("c:\windows\system32")
;pwrshl_cmd =  'ipconfig' ; This works OK
pwrshl_cmd = "(Get-ItemProperty hal.dll).VersionInfo.FileVersion" ; This fails!

;RunWait( "powershell.exe", "-noexit -command & %pwrshl_cmd%" )
RunWait( "powershell.exe", "-noexit %pwrshl_cmd%" )


This produces the following error in PowerScript:

Get-ItemProperty : Cannot find path 'C:\windows\system32\hal.dll' because it does not exist.
At line:1 char:4
+ & (Get-ItemProperty hal.dll).VersionInfo.FileVersion
+    ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\windows\system32\hal.dll:String) [Get-ItemProperty], ItemNotFoundExc
   eption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command
name, a script block, or a CommandInfo object.
At line:1 char:3
+ & (Get-ItemProperty hal.dll).VersionInfo.FileVersion
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : BadExpression

PS C:\windows\system32>


Thanks JW

stanl

  • Pundit
  • *****
  • Posts: 777
Re: PowerShell Path Issue
« Reply #1 on: January 30, 2018, 03:55:10 am »
Maybe

pwrshl_cmd = "(Get-ItemProperty 'c:\windows\system32\hal.dll').VersionInfo.FileVersion"

Jeremy Whilde

  • Jr. Member
  • **
  • Posts: 50
Re: PowerShell Path Issue
« Reply #2 on: January 30, 2018, 06:34:35 am »

Maybe

pwrshl_cmd = "(Get-ItemProperty 'c:\windows\system32\hal.dll').VersionInfo.FileVersion"

No this still fails, I do know that it can be very tricky to get the exact input format correct for PS and the security is a real challenge.

Thanks JW

stanl

  • Pundit
  • *****
  • Posts: 777
Re: PowerShell Path Issue
« Reply #3 on: January 30, 2018, 08:34:29 am »

No this still fails, I do know that it can be very tricky to get the exact input format correct for PS and the security is a real challenge.

Thanks JW

Well, I have no problems running PS code from WB - but I use the CLR option and run PS code directly. You might consider trying that.