powershell PowerShell:获取当前正在运行的程序的策略

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell:获取当前正在运行的程序的策略相关的知识,希望对你有一定的参考价值。

function Get-RunningPolicyGuid {
	[CmdletBinding(SupportsShouldProcess=$True,DefaultParameterSetName="None")]
	PARAM()

	$parentPolicyGuid = "{00000000-0000-0000-0000-000000000000}"
	try {
		# Connect to the local base agent
		$IAeXClient = New-Object -ComObject Altiris.AeXClient -ErrorAction Stop
		# Connect to the local software delivery agent
		$IAeXSWDAgent = $IAeXClient.Agent("Altiris.SWD")
		# Get the advertisementId Guid of the currently running policy
		$advertisementId = ([Guid]$IAeXSWDAgent.RunningProgram.Id).ToString('B').ToUpper()
		Write-Verbose "advertisementId: $($advertisementId)"
		if ($advertisementId) {
			# Get Software Delivery directories (they can span multiple drives
			$SWDInstallDirs = $IAeXSWDAgent.Packages | ? {$_.CacheFolder} | Select -ExpandProperty CacheFolder | Select @{Name="SWDInstallDir";Expression={$_.Substring(0,$_.indexof('{'))}} -Unique | Select -ExpandProperty SWDInstallDir
			foreach ($SWDInstallDir In $SWDInstallDirs) {
				$AeXSWDPolicyXmlPath = "$($SWDInstallDir)AeXSWDPolicy.xml"
				Write-Verbose "Testing: $($AeXSWDPolicyXmlPath)"
				# Test that the path exists
				if (Test-Path -Path $AeXSWDPolicyXmlPath -PathType Leaf) {
					Write-Verbose "Getting contents"
					# Get the contents of the XML file as XML
					$AeXSWDPolicyXml = [xml](Get-Content -Path $AeXSWDPolicyXmlPath)
					# Locate the policy guid for the advertisement
					$parentPolicyGuid = $AeXSWDPolicyXml.SWD.Advertisements.Advertisement | ? {$_.Id -eq $advertisementId} | Select -ExpandProperty "parentPolicyGuid"
					if ($parentPolicyGuid) {
						Write-Verbose "Policy Guid found. ($($parentPolicyGuid))"
						break
					}
				}
			}
		}
		$parentPolicyGuid
	} catch {
		$parentPolicyGuid
	} finally {
		if ($IAeXClient) {
			# Destroy the COM Object if it exists
	        [System.Runtime.InteropServices.Marshal]::ReleaseComObject($IAeXClient) | Out-Null
		}
	}
}

以上是关于powershell PowerShell:获取当前正在运行的程序的策略的主要内容,如果未能解决你的问题,请参考以下文章

Powershell:从 Receive-Job 获取输出

powershell入门

如何使用 AZ Powershell 获取 VMSize 的成本/月?

使用 powershell 获得计数器性能

powershell 获取Powershell函数的定义/正文

powershell PowerShell获取文件名