Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. clear
  2. #$ErrorActionPreference = "silentlycontinue"
  3.  
  4. $Logfile = "C:tempNEWnetbackup_version.log"
  5.  
  6. Function LogWrite
  7. {
  8. param([string]$logstring)
  9.  
  10. Add-Content $Logfile -Value $logstring
  11. }
  12.  
  13. $computer = Get-Content -Path c:tempnetbackup_servers1.txt
  14.  
  15. foreach ($computer1 in $computer){
  16.  
  17. $Service = Get-WmiObject Win32_Service -Filter "Name = 'NetBackup Client Service'" -ComputerName $computer1
  18.  
  19. if (test-connection $computer1 -quiet)
  20. {
  21. $NetbackupVersion1 = $(Get-ItemProperty hklm:SOFTWAREVeritasNetBackupCurrentVersion).PackageVersion
  22.  
  23. if($Service.state -eq 'Running')
  24. {
  25. LogWrite "$computer1 STARTED $NetbackupVersion1"
  26. }
  27. else
  28. {
  29. LogWrite "$computer1 STOPPED $NetbackupVersion1"
  30. }
  31. }
  32. else
  33. {
  34. LogWrite "$computer1 is down" -foregroundcolor RED
  35. }
  36. }
  37.  
  38. $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer1)
  39. $RegKey= $Reg.OpenSubKey("SOFTWARE\Veritas\NetBackup\CurrentVersion")
  40. $NetbackupVersion1 = $RegKey.GetValue("PackageVersion")
  41.  
  42. Import-Module PSRemoteRegistry
  43. Get-RegValue -ComputerName $Computer1 -Key SOFTWAREVeritasNetBackupCurrentVersion -Value PackageVersion
  44.  
  45. $Session = New-PSSession -ComputerName $Computer1 -Authentication CredSSP
  46. $NetbackupVersion1 = Invoke-Command -Session $Session -ScriptBlock { $(Get-ItemProperty hklm:SOFTWAREVeritasNetBackupCurrentVersion).PackageVersion}
  47. Remove-PSSession $Session
  48.  
  49. $w32reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computer1)
  50. $keypath = 'SOFTWAREVeritasNetBackupCurrentVersion'
  51. $netbackup = $w32reg.OpenSubKey($keypath)
  52. $NetbackupVersion1 = $netbackup.GetValue('PackageVersion')
  53.  
  54. <# Replace following domain.name with yours and userAccountName with remote username #>
  55. $userLogin = New-Object System.Security.Principal.NTAccount(“domain.name“,”userAccountName“)
  56. $userSID = $userLogin.Translate([System.Security.Principal.SecurityIdentifier])
  57.  
  58. <# We will open HKEY_USERS and with accurate user’s SID from remoteComputer #>
  59. $remoteRegistry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘Users’,”remoteComputer“)
  60.  
  61. <# We will then retrieve LocalName value from Control Panel / International subkeys #>
  62.  
  63. $key = $userSID.value+”Control PanelInternational”
  64. $openKey = $remoteRegistry.OpenSubKey($key)
  65.  
  66. <# We can now retrieve any values #>
  67.  
  68. $localName = $openKey.GetValue(‘LocaleName’)
  69.  
  70. import wmi
  71.  
  72. conn = wmi.WMI('172.20.58.34', user='UserName', password='Password')
  73. command = r'cmd /c reg query "HKLMSOFTWAREMicrosoft" /ve > C:output.txt'
  74. conn.Win32_Process.Create(CommandLine=command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement