I am trying to delete a registry key from windows machines by invoke method. Is there any way to write the output for the cmdlet (Remove-ItemProperty) or any other alternate to know whether the key is deleted or not.
$csvpath=""
$Credential= Get-Credential -Message "Enter the password for Administrator User" -UserName "Administrator"
$script = @'
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
if([IntPtr]::Size -eq 8){
$text = Remove-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent\" -Name 'AgentGUID' -Force -ErrorAction SilentlyContinue
%{"$($_.AgentGUID)"}
}
elseif([IntPtr]::Size -eq 4){
$text = Remove-ItemProperty -Path "HKLM:\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\" -Name 'AgentGUID' -Force -ErrorAction SilentlyContinue
}
$text
'@
foreach($vmsincsv in (Import-CSV -Path $csvpath -UseCulture)){
$vm = Get-VM $vmsincsv.name
Invoke-VMScript -VM $vm -GuestCredential $Credential -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput
}