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
Maybe
pwrshl_cmd = "(Get-ItemProperty 'c:\windows\system32\hal.dll').VersionInfo.FileVersion"
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
Quote from: Jeremy Whilde on January 30, 2018, 06:34:35 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.