/build/static/layout/Breadcrumb_cap_w.png

K1000 PS Custom Inventory runs fine in PS, not in KACE

I have a small shell command i'm running to eventually get a date and time.

Get-WmiObject -ComputerName '.' -Class Win32_UserProfile -Filter "Special='False'" | select @{Name='LastUsed';Expression={$_.ConvertToDateTime($_.LastUseTime)}}| sort LastUsed -Descending | select-object -first 1 | format-table –hidetableheaders

It Returns:  7/25/2016 12:57:58 PM   
This command works just fine in PowerShell and as a Custom Inventory. 

But i needed to change the date to sort properly.  So i updated the command to this:

Get-WmiObject -ComputerName '.' -Class Win32_UserProfile -Filter "Special='False'" | select @{Name='LastUsed';Expression={$_.ConvertToDateTime($_.LastUseTime).TOSTRING("yyyy-MM-dd HH:mm:ss")}}| sort LastUsed -Descending | select-object -first 1 | format-table –hidetableheaders

It returns: 2016-07-25 12:57:58 

This one works just fine in Powerhsell, but fails as a Custom Inventory with this error:
'Missing ')' in method call.
At line:1 char:171
+ & {(Get-WmiObject -ComputerName '.' -Class Win32_UserProfile -Filter Special=
'False' | select @{Name='LastUsed';Expression={$_.ConvertToDateTime($_.LastUseT
ime).TOSTRING( <<<< yyyy-MM-dd HH:MM)}}| sort LastUsed -Descending | select-obj
ect -first 1 | format-table -hidetableheaders)}
   + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], Paren
  tContainsErrorRecordException
   + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

'

Any ideas on how to get around it?    It seems to have to do with the double parenthesis inside double parenthesis.  But i can't figure out how to get the command written to work in the Custom Inventory.

Here is the actual Custom inventory text for:

The one that works:

ShellCommandTextReturn(powershell.exe -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& {(Get-WmiObject -ComputerName '.' -Class Win32_UserProfile -Filter "Special='False'" | select @{Name='LastUsed';Expression={$_.ConvertToDateTime($_.LastUseTime)}}| sort LastUsed -Descending | select-object -first 1 | format-table –hidetableheaders)})
That one that doesn't work:
ShellCommandTextReturn(powershell.exe -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& {(Get-WmiObject -ComputerName '.' -Class Win32_UserProfile -Filter "Special='False'" | select @{Name='LastUsed';Expression={$_.ConvertToDateTime($_.LastUseTime).TOSTRING("yyyy-MM-dd HH:mm:ss")}}| sort LastUsed -Descending | select-object -first 1 | format-table –hidetableheaders)})


1 Comment   [ + ] Show comment
  • What happens if you change the double quotes to single quotes in TOSTRING("yyyy-MM-dd HH:mm:ss")

    TOSTRING('yyyy-MM-dd HH:mm:ss') - flip1001 7 years ago

Answers (0)

Be the first to answer this question

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ