Powershell - How to get the Output without the VariableValue when using WMIC

Rodolfo Pena Cedeno 26 Reputation points
2022-10-18T08:40:22.81+00:00

Good Afternoon, I trust this finds you all very well.

I am learning powershell and i will really appreciate if someone could please help me with the following : i am not able to get only the output when using the following wmic cmd:

wmic OS Get DataExecutionPrevention_SupportPolicy  

This is what i am getting from that line:

PS C:\_Admin_RPC> wmic OS Get DataExecutionPrevention_SupportPolicy  

DataExecutionPrevention_SupportPolicy   

 
2  

                                

I have tried many thing but it is not working, i would be grateful if someone could please help me.

What i am planing to do is to save the value (2) in a variable and then use write-output to return $true if the value is the one that i am looking for.

Thank you and best regards.

Peace

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,430 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 32,441 Reputation points
    2022-10-18T12:42:16.837+00:00

    Don't use wmic.exe, that utility is being deprecated. Use the native PS cmdlet's.

    $myVar = (Get-CimInstance win32_operatingsystem).DataExecutionPrevention_SupportPolicy  
    
     
    
    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,416 Reputation points
    2022-10-18T14:35:48.227+00:00

    @MotoX80 is correct -- use the PowerShell cmdlets.

    The wmic.exe is a DOS executable. The value returned (when you run it as you did) is six lines of text.

    What you really wanted is the value associated with the CIM object's property whose name is DataExecutionPrevention_SupportPolicy.

    If you're learning PowerShell, I've suggested this free PDF before: Windows-PowerShell-4. work your way through the 1st half of the book and do the exercises. When you feel more confident in your understanding of PowerShell, go ahead and read the 2nd half. The 2nd half covers using PowerShell in accomplishing common administrative tasks, using what you've learned from the 1st half.

    0 comments No comments

  2. Rodolfo Pena Cedeno 26 Reputation points
    2022-10-19T15:16:11.027+00:00

    At the end this is the solution that i am using based on the scenario that i am facing:

    $value = Get-CimInstance -ClassName win32_operatingsystem | Select-Object -Property 'DataExecutionPrevention_SupportPolicy'  
      
    $value = $value.DataExecutionPrevention_SupportPolicy  
      
    if($value -eq 1){  
        Write-Output $true  
    }  
    

    Thank you very much guys for your help and support.

    Peace