Hopefully somone can point me in the right direction as to what i am doing wrong here.
I've written a PS script that takes a hostname (or IP) input and then queries a remote host gets the data and returns it in the statistics format as required by SAM.
I am logged into the SW server as the service account that is specified in my template and i can run the PS sucesfully against our server estate (i tried 30 servers and got the results i was expecting).
My issue is when i put the same script into the template and run it from the, it always returns "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" as the script result.
i have posted an excerpt of the script below.
it's passed one variable which is the hostname and can be tested by replacing the SERVERNAME value in line 5
---Begin ---
Try {
$CBSRebootPend = $null
$HKLM = [UInt32] "0x80000002"
$WMI_Reg = [WMIClass] "\\SERVERNAME\root\default:StdRegProv"
$RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
$CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"
Write-Host "Message.CBServicing: " $CBSRebootPend
if ($CBSRebootPend) {
Write-Host "Statistic.CBServicing: 3"
} else {
Write-Host "Statistic.CBServicing: 2"
}
Write-host "Message.Errors: None"
Write-host "Statistic.Errors: 2"
} catch {
Write-Host "Message.CBServicing: Unknown"
Write-Host "Statistic.CBServicing: 4"
Write-Host "Message.WindowsUpdate: Unknown"
Write-host "Message.Errors: Line "$_.InvocationInfo.ScriptLineNumber " -- " $_.Exception.Message
Write-host "Statistic.Errors: 4"
}
exit(0)
--- End ---