Powershell Registry value to be used as variable
I'd forget shelling out to REG.EXE and use native PowerShell commands (in this instance, you need a bit of .NET magic):
function getAgentGUID() {
param( [String] $computername = "" );
[String] $Local:strServerName = $computername;
[Microsoft.Win32.RegistryKey] $Local:objHKLMRootRegKey = $null;
[Microsoft.Win32.RegistryKey] $Local:objMyKey = $null;
[String] $Local:strAgentGUID = "";
try {
$objHKLMRootRegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( [Microsoft.Win32.RegistryHive]::LocalMachine, $strServerName )
try {
$objMyKey = $objHKLMRootRegKey.OpenSubKey( "SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Agent" );
$strAgentGUID = $objMyKey.GetValue( "Agentguid" );
} #try
catch {
Write-Error -Message "ERROR : Failed to get AgentGUID value.";
} #catch
} #try
catch {
Write-Error -Message "ERROR : Failed to connect to remote registry.";
} #catch
return $strAgentGUID;
}
#
# Get the McAfee agent GUID for remote machine called fred.
#
[String] $Local:strAgentGUID = getAgentGUID -computer "fred";
Write-Host -foregroundColor "red" -backgroundColor "white" -Object ( "GUID is : [" + $strAgentGUID + "]" );
exit;