У меня есть сценарий, который соответствует значениям времени реестра и значениям времени сервера. также у меня есть скрипт sccm simple fix. и главное, чего я пытаюсь достичь, - дважды вызвать значения реестра и значения сервера в главном скрипте. (До и после), и я заикаться, как я не могу понять, почему мой compairing скрипт не работает во второй раз или показывая в то же время, как при первом запуске сценария:Функции PS в функции, как позвонить второй раз
#SCCM script START
Function Get-Sccm-Repair-test_01 {
PARAM(
[Parameter(Mandatory=$true)]
[string]$computer
)
###############
#Start Trigering Application Deployment Evaluation Cycle#
Function get-sccm-reg-values {
param(
[string]$computer
,[string]$Path= "HKLM\SOFTWARE\Danskebank\Agent Status"
,[string[]]$Properties
,[switch]$Verbose
)
if ($Verbose) { $VerbosePreference = 2 }
$root, $last = $Path.Split("\")
$last = $last[-1]
$Path = $Path.Substring($root.Length + 1,$Path.Length - ($last.Length + $root.Length + 2))
$root = $root.TrimEnd(":")
switch($root) {
"HKCR" { $root = "ClassesRoot"}
"HKCU" { $root = "CurrentUser" }
"HKLM" { $root = "LocalMachine" }
"HKU" { $root = "Users" }
"HKPD" { $root = "PerformanceData"}
"HKCC" { $root = "CurrentConfig"}
"HKDD" { $root = "DynData"}
default { return "Path argument is not valid" }
}
#Access Remote Registry Key using the static OpenRemoteBaseKey method.
Write-Verbose "Accessing $root from $computer"
$rootkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($root,$computer)
if(-not $rootkey) { Write-Error "Can't open the remote $root registry hive" }
Write-Verbose "Opening $Path"
$key = $rootkey.OpenSubKey($Path)
if(-not $key) { Write-Error "Can't open $($root + '\' + $Path) on $computer" }
$subkey = $key.OpenSubKey($last)
$output = new-object object
if($subkey -and $Properties -and $Properties.Count) {
foreach($property in $Properties) {
Add-Member -InputObject $output -Type NoteProperty -Name $property -Value $subkey.GetValue($property)
}
Write-Output $output
} elseif($subkey) {
foreach($property in $subkey.GetValueNames())
{
Add-Member -InputObject $output -Type NoteProperty -Name $property -Value $subkey.GetValue($property)
}
}
$pcTime = invoke-command -ComputerName $computer -ScriptBlock {Get-Date -DisplayHint Date -Format yyyy-MM-dd}
$SCCMValue = $pcTime | Out-String
$Rserver = $output.SCCMTimestamp | Out-String
if($SCCMValue -eq $Rserver)
{
Write-Host -foreground "green" "Server curent date:" $pcTime
Write-Host -foreground "green" "SCCM Registry Value is up to date:" $output.SCCMTimestamp
}
else
{
Write-Host -foreground "red" "Server curent date:" $pcTime
Write-Host -foreground "red" "SCCM Registry Value is outdate:" $output.SCCMTimestamp
}
$key = Out-Null
$pcTime = Out-Null
}
#END Trigering Application Deployment Evaluation Cycle#
###############
###############
#Start Trigering Application Deployment Evaluation Cycle#
$SCCMClient = [wmiclass] "\\$computer\root\ccm:SMS_client"
Write-Host -foreground "green" "Application Deployment Evaluation Cycle Updated"
$SCCMClient.TriggerSchedule("{00000000-0000-0000-0000-000000000121}") | Out-Null
Write-Host -foreground "green" "Machine Policy Retrieval and Evaluation Cycle Updated"
$SCCMClient.TriggerSchedule("{00000000-0000-0000-0000-000000000021}") | Out-Null
#Stop Trigering Application Deployment Evaluation Cycle#
###############
Write-Host -foreground "green" "Gathering data for pending install packages..."
$SoftwareApp = Get-WmiObject -Namespace ROOT\ccm\ClientSDK -Class CCM_Application -ComputerName $computer | Select-Object AllowedActions, Fullname | FT -AutoSize
Write-Host -foreground "green" "Installing Deployment Test (SCCMTimestamp) package..."
#Start Trigering the SCCM package#
$AppName = "Deployment Test (SCCMTimestamp)"
$s = New-PSSession -ComputerName $Computer
Invoke-Command -Session $s -Argu $Computer,$AppName -ScriptBlock `
{
param ($Computer,$AppName)
write-host "Getting Parameters for '$AppName' on $Computer"
$App = Get-WmiObject -computername $Computer -Namespace "root\ccm\ClientSDK" -Class CCM_Application | where {$_.Name -like "$AppName"} | Select-Object Id, Revision, IsMachineTarget
$AppID = $App.Id
$AppRev = $App.Revision
$AppTarget = $App.IsMachineTarget
write-host $AppID, $AppRev, $AppTarget -ForegroundColor Yellow
write-host "Triggering Installation!" -ForegroundColor Green
([wmiclass]'ROOT\ccm\ClientSdk:CCM_Application').Install($AppID, $AppRev, $AppTarget, 0, 'Normal', $False) | Out-Null
}
Remove-PSSession $s
#End Trigering the SCCM package#
#Restarting the service.START
Write-Host -foreground "green" "Restarting the HealthService..."
$session = New-PSsession -Computername $computer
Invoke-Command -Session $Session -ScriptBlock {Restart-Service "HealthService"} | Out-Null
Remove-PSSession $Session
#Resstarting the service.END
################ Double check the time START
Function get-sccm-reg-values {
param(
[string]$Path = "HKLM\SOFTWARE\Danskebank\Agent Status"
,[string[]]$Properties
,[switch]$Verbose
)
if ($Verbose) { $VerbosePreference = 2 }
$root, $last = $Path.Split("\")
$last = $last[-1]
$Path = $Path.Substring($root.Length + 1,$Path.Length - ($last.Length + $root.Length + 2))
$root = $root.TrimEnd(":")
switch($root) {
"HKCR" { $root = "ClassesRoot"}
"HKCU" { $root = "CurrentUser" }
"HKLM" { $root = "LocalMachine" }
"HKU" { $root = "Users" }
"HKPD" { $root = "PerformanceData"}
"HKCC" { $root = "CurrentConfig"}
"HKDD" { $root = "DynData"}
default { return "Path argument is not valid" }
}
#Access Remote Registry Key using the static OpenRemoteBaseKey method.
Write-Verbose "Accessing $root from $computer"
$rootkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($root,$computer)
if(-not $rootkey) { Write-Error "Can't open the remote $root registry hive" }
Write-Verbose "Opening $Path"
$key = $rootkey.OpenSubKey($Path)
if(-not $key) { Write-Error "Can't open $($root + '\' + $Path) on $computer" }
$subkey = $key.OpenSubKey($last)
$output = new-object object
if($subkey -and $Properties -and $Properties.Count) {
foreach($property in $Properties) {
Add-Member -InputObject $output -Type NoteProperty -Name $property -Value $subkey.GetValue($property)
}
Write-Output $output
} elseif($subkey) {
foreach($property in $subkey.GetValueNames())
{
Add-Member -InputObject $output -Type NoteProperty -Name $property -Value $subkey.GetValue($property)
}
}
$pcTime = invoke-command -ComputerName $computer -ScriptBlock {Get-Date -DisplayHint Date -Format yyyy-MM-dd}
$SCCMValue = $pcTime | Out-String
$Rserver = $output.SCCMTimestamp | Out-String
if($SCCMValue -eq $Rserver)
{
Write-Host -foreground "green" "Server curent date:" $pcTime
Write-Host -foreground "green" "SCCM Registry Value is up to date:" $output.SCCMTimestamp
}
else
{
Write-Host -foreground "red" "Server curent date:" $pcTime
Write-Host -foreground "red" "SCCM Registry Value is outdate:" $output.SCCMTimestamp
}
}
############### Double check the time END
Write-Host -foreground "green" "SCCM fix has been performed, please wait from 5 to 10 minutes untill event close in scom.."
}
#SCCM script END
Благодаря