Hi
I am trying to fetch a registry value for AV. The reg value of agentguid is in different locations for 32bit and 64bit OS.
Here I want the information like if the OS is 64-bit write the reg value if not check for 32 bit path and write the value.
One more step if the OS is neither 32-bit or 64-bit and doesn't find the any registry value it should check the "McAfee Framework Service" and write the status.
32-Bit: [HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\]
64-Bit: [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Agent\]
$testcode = @'
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" |%{"$($_.AgentGUID)"} -ErrorAction SilentlyContinue
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" | %{"$($_.Name) is $($_.Status)"}
}
$text
'@
$testout=Invoke-VMScript -VM "VM1" -GuestUser "administrator" -GuestPassword "admin@123" -ScriptText $testcode -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
$testout
Output for 64bit:
The 32-/64- bit entries were switched
if([IntPtr]::Size -eq 8){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 4){
$text = Get-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" -ErrorAction SilentlyContinue | %{"$($_.Name) is $($_.Status)"}
if(-not $text){
$text = Get-Service -Name wuauserv | Select -First 1 |
%{"$($_.Name) is $($_.Status)"}
}
}
$text
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
$testCode = @'
if([IntPtr]::Size -eq 8){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" |%{"$($_.AgentGUID)"}
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" | %{"$($_.Name) is $($_.Status)"}
}
}
elseif([IntPtr]::Size -eq 4){
$text = Get-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" |%{"$($_.AgentGUID)"}
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" | %{"$($_.Name) is $($_.Status)"}
}
}
else{
$text = Get-Service -Name "McAfee Framework Service" | %{"$($_.Name) is $($_.Status)"}
}
$text
'@
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Its working if the vm is 64 or 32 but on the 3rd condition its failing if vm doesn't have Antivirus there it should write some service like wuauserv.
Its not writing. Is it possible to suppress the error when using Get-ItemProperty and move to next condition.
Script used is for invoke
$script = @'
if([IntPtr]::Size -eq 8){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" |%{"$($_.AgentGUID)"} -ErrorAction SilentlyContinue
}
elseif([IntPtr]::Size -eq 4){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" |%{"$($_.AgentGUID)"} -ErrorAction SilentlyContinue
}
else{
$text = Get-Service -Name wuauserv | Select -first 1 | %{"$($_.Name) is $($_.Status)"}
}
$text
'@
Try like this
if([IntPtr]::Size -eq 4){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 8){
$text = Get-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" -ErrorAction SilentlyContinue | %{"$($_.Name) is $($_.Status)"}
if(-not $text){
$text = Get-Service -Name wuauserv | Select -First 1 |
%{"$($_.Name) is $($_.Status)"}
}
}
$text
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Its not showing correct results. Even though the registry path available its just writing wuauserv is Stopped.
Executed on single machine as below.
if([IntPtr]::Size -eq 4){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 8){
$text = Get-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" -ErrorAction SilentlyContinue | %{"$($_.Name) is $($_.Status)"}
if(-not $text){
$text = Get-Service -Name wuauserv | Select -First 1 |
%{"$($_.Name) is $($_.Status)"}
}
}
$text
If I executed as single.
The 32-/64- bit entries were switched
if([IntPtr]::Size -eq 8){
$text = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 4){
$text = Get-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
}
if(-not $text){
$text = Get-Service -Name "McAfee Framework Service" -ErrorAction SilentlyContinue | %{"$($_.Name) is $($_.Status)"}
if(-not $text){
$text = Get-Service -Name wuauserv | Select -First 1 |
%{"$($_.Name) is $($_.Status)"}
}
}
$text
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I found the actual problem. After replacing this line for 32bit now it working.
Get-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\"-ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}
Replaced to
Get-ItemProperty -Path "HKLM:\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\"-ErrorAction SilentlyContinue |
%{"$($_.AgentGUID)"}