Don't use wmic.exe, that utility is being deprecated. Use the native PS cmdlet's.
$myVar = (Get-CimInstance win32_operatingsystem).DataExecutionPrevention_SupportPolicy
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
Don't use wmic.exe, that utility is being deprecated. Use the native PS cmdlet's.
$myVar = (Get-CimInstance win32_operatingsystem).DataExecutionPrevention_SupportPolicy
@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.
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