public void Harvest(ServerConfig server) { var result = _executor.Execute(server, @"$regKeys = @( ""HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client"", ""HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"", ""HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5"", ""HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0"", ""HKLM:\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727"", ""HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322"" ) $result = @() foreach($regKeyPath in $regKeys) { if(test-path $regKeyPath) { $regKey = Get-Item $regKeyPath $installed = $regKey.GetValue(""Install"") if($installed) { $dotNetVersion = @{} $dotNetVersion.Installed = $installed $dotNetVersion.Version = $regKey.GetValue(""Version"") $dotNetVersion.ServicePack = $regKey.GetValue(""SP"") $dotNetVersion.Release = $regKey.GetValue(""Release"") $dotNetVersion.TargetVersion = $regKey.GetValue(""TargetVersion"") $dotNetVersion.Client = $regKey.Name.ToLower().EndsWith(""client"") $dotNetVersion.Full = $regKey.Name.ToLower().EndsWith(""full"") $result += ,@($dotNetVersion) } } } return $result", mod => mod.LoadConDepModule = false, logOutput: false); foreach (var element in result) { server.GetServerInfo().DotNetFrameworks.Add(element); } }
public override void Execute(ServerConfig server, IReportStatus status, ConDepSettings settings, CancellationToken token) { var canPingServer = CanPingServer(server); var startNodeOperation = new StartConDepNodeOperation(); Logger.Verbose(string.Format("Can {0}use ping for validation", canPingServer ? "" : "NOT ")); Logger.WithLogSection("Restarting", () => { Logger.Info(string.Format("Executing restart command on server {0}", server.Name)); var powershellExecutor = new PowerShellExecutor(); powershellExecutor.Execute(server, string.Format("cmd /c \"shutdown /r /t {0}\"", _delayInSeconds)); if (canPingServer) { Logger.Verbose("Waiting for ping to fail"); Logger.Info("Waiting for server to stop responding"); WaitForPing(WaitForStatus.Failure, server); Logger.Info("Server stopped responding"); Logger.Verbose("Waiting for ping to Succeed"); Logger.Info("Waiting for server to respond again"); WaitForPing(WaitForStatus.Success, server); Logger.Info("Server started to respond"); } else { Logger.Verbose("Waiting for WinRM to fail"); Logger.Info("Waiting for server to stop responding"); WaitForWinRm(WaitForStatus.Failure, server); Logger.Info("Server stopped responding"); } Logger.Verbose("Waiting for WinRM to succeed"); Logger.Info("Waiting for server to respond to PowerShell commands"); WaitForWinRm(WaitForStatus.Success, server); Logger.Info("Serve successfully responds to PowerShell commands"); Logger.Info("Computer successfully restarted"); Logger.WithLogSection("Starting ConDepNode", () => startNodeOperation.Execute(server, status, settings, token)); }); }
public Result Execute(ServerConfig server, ConDepSettings settings, CancellationToken token) { var assemblyLocalDir = Path.GetDirectoryName(GetType().Assembly.Location); var assemblyRemoteDir = Path.Combine(server.GetServerInfo().TempFolderDos, "Assemblies"); var publisher = new FilePublisher(); publisher.PublishDirectory(assemblyLocalDir, assemblyRemoteDir, server, settings); var remoteAssemblyFileName = Path.Combine(Path.Combine(server.GetServerInfo().TempFolderPowerShell, "Assemblies"), Path.GetFileName(GetType().Assembly.Location)); var remoteJsonAssembly = Path.Combine(Path.Combine(server.GetServerInfo().TempFolderPowerShell, "Assemblies"), "Newtonsoft.Json.dll"); var typeName = GetType().FullName; var loggerTypeName = typeof(RemotePowerShellLogger).FullName; var parameters = GetPowerShellParameters(ConstructorArguments, GetType()).ToList(); var scriptParams = string.Join(",", parameters.Select(x => "$" + x.Name)); var argumentList = string.Join(",", GetType().GetConstructor(ConstructorArguments.Select(x => x.GetType()).ToArray()).GetParameters() .Select(x => "$" + x.Name)); var deserializeScript = GetDeserializationScript(GetType() .GetConstructor(ConstructorArguments.Select(x => x.GetType()).ToArray())); var psExecutor = new PowerShellExecutor(); var script = string.Format(@" Param({3}) add-type -path {0} add-type -path {5} {4} $operation = new-object -typename {1} -ArgumentList {6} $logger = new-object -typename {2} -ArgumentList (Get-Host).UI $operation.Execute($logger) ", remoteAssemblyFileName, typeName, loggerTypeName, scriptParams, deserializeScript, remoteJsonAssembly, argumentList); psExecutor.Execute(server, script, null, parameters); return(Result.SuccessChanged()); }
public void Harvest(ServerConfig server) { var diskInfo = @"$disks = Get-WmiObject win32_logicaldisk $result = @() foreach($disk in $disks) { $diskInfo = @{} $diskInfo.DeviceId = $disk.DeviceID $diskInfo.Size = $disk.Size $diskInfo.FreeSpace = $disk.FreeSpace $diskInfo.Name = $disk.Name $diskInfo.FileSystem = $disk.FileSystem $diskInfo.VolumeName = $disk.VolumeName $result += ,@($diskInfo) } return $result"; var diskInfoResult = _executor.Execute(server, diskInfo, mod => mod.LoadConDepModule = false, logOutput: false); if (diskInfoResult != null) { foreach (var disk in diskInfoResult) { var d = new DiskInfo { DeviceId = disk.DeviceId, SizeInKb = disk.Size == null ? 0 : Convert.ToInt64(disk.Size / 1024), FreeSpaceInKb = disk.FreeSpace == null ? 0 : Convert.ToInt64(disk.FreeSpace / 1024), Name = disk.Name, FileSystem = disk.FileSystem, VolumeName = disk.VolumeName }; server.GetServerInfo().Disks.Add(d); } } }
public override void Execute(ServerConfig server, IReportStatus status, ConDepSettings settings, CancellationToken token) { var psExecutor = new PowerShellExecutor(); psExecutor.Execute(server, string.Format("[Environment]::SetEnvironmentVariable(\"{0}\", \"{1}\", \"{2}\")", _name, _value, _target)); }
public void Harvest(ServerConfig server) { var osInfo = @" $osInfo = @{} try { $perfData = Get-WmiObject win32_perfformatteddata_perfos_system -Property SystemUpTime $osInfo.SystemUpTime = $perfData.SystemUpTime } catch { write-warning 'Failed to retreive SystemUpTime through WMI. Probably because of a bug in Windows/WMI when the server has been running close to a year without reboot.' } $compSystem = Get-WmiObject win32_computersystem -Property Name,SystemType $os = Get-WmiObject win32_operatingsystem -Property Caption,Version,BuildNumber $osInfo.HostName = $compSystem.Name $osInfo.SystemType = $compSystem.SystemType $osInfo.Name = $os.Caption $osInfo.Version = $os.Version $osInfo.BuildNumber = $os.BuildNumber $osInfo.ProgramFilesFolder = ${Env:ProgramFiles} $osInfo.ProgramFilesX86Folder = ${Env:ProgramFiles(x86)} $regKeys = @() if(Test-Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall) { $regKeys += 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall' } if(Test-Path HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall) { $regKeys += 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' } if(Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall) { $regKeys += 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall' } [array] $packages = Get-ChildItem -Path $regKeys | Get-ItemProperty | where-object { $_.DisplayName -ne $null } | select-object -Property DisplayName,DisplayVersion | foreach{$_.DisplayName + "";"" + $_.DisplayVersion} if($packages -eq $null) { $packages = @() } $osInfo.InstalledSoftwarePackages = $packages return $osInfo "; var osInfoResult = _executor.Execute(server, osInfo, mod => mod.LoadConDepModule = false, logOutput: false) .FirstOrDefault(); if (osInfoResult != null) { server.GetServerInfo().OperatingSystem = new OperatingSystemInfo { BuildNumber = Convert.ToInt32(osInfoResult.BuildNumber), Name = osInfoResult.Name, HostName = osInfoResult.HostName, SystemType = osInfoResult.SystemType, SystemUpTime = TimeSpan.FromSeconds(Convert.ToDouble(osInfoResult.SystemUpTime)), Version = osInfoResult.Version, ProgramFilesFolder = osInfoResult.ProgramFilesFolder, ProgramFilesX86Folder = osInfoResult.ProgramFilesX86Folder, InstalledSoftwarePackages = ConvertPackagesStringArrayToObjectCollection( ((ArrayList)((PSObject)osInfoResult.InstalledSoftwarePackages).BaseObject).Cast <string>().ToArray()) }; Logger.Verbose("Output from harvester:"); Logger.Verbose("BuildNumber : " + osInfoResult.BuildNumber); Logger.Verbose("Name : " + osInfoResult.Name); Logger.Verbose("HostName : " + osInfoResult.HostName); Logger.Verbose("SystemType : " + osInfoResult.SystemType); Logger.Verbose("SystemUpTime : " + osInfoResult.SystemUpTime); Logger.Verbose("Version : " + osInfoResult.Version); Logger.Verbose("ProgramFiles : " + osInfoResult.ProgramFilesFolder); Logger.Verbose("ProgramFilesX86 : " + osInfoResult.ProgramFilesX86Folder); Logger.Verbose("InstalledPackages:"); server.GetServerInfo().OperatingSystem.InstalledSoftwarePackages.ToList() .ForEach(x => Logger.Verbose("\t" + x.DisplayName + ", version: " + x.DisplayVersion)); } }
public void Harvest(ServerConfig server) { var networkInfo = @"$result = @() $networkInterfaces = Get-WmiObject win32_networkadapterconfiguration | where { $_.IPEnabled } foreach($interface in $networkInterfaces) { $ifaceInfo = @{} $ifaceInfo.IPAddresses = $interface.IPAddress $ifaceInfo.IPSubnets = $interface.IPSubnet $ifaceInfo.Description = $interface.Description $ifaceInfo.DefaultGateways = $interface.DefaultIPGateway $ifaceInfo.DHCPEnabled = $interface.DHCPEnabled $ifaceInfo.DNSDomain = $interface.DNSDomain $ifaceInfo.DNSHostName = $interface.DNSHostName $ifaceInfo.Index = $interface.Index $ifaceInfo.InterfaceIndex = $interface.InterfaceIndex $result += ,@($ifaceInfo) } return $result"; var networkInfoResult = _executor.Execute(server, networkInfo, mod => mod.LoadConDepModule = false, logOutput: false); if (networkInfoResult != null) { foreach (var network in networkInfoResult) { //object[] ipAddresses = network.IPAddresses; //IEnumerable<string> ipAddresses2 = ipAddresses.Cast<string>(); //object[] gateways = network.DefaultGateways; var info = new NetworkInfo { Description = network.Description, DHCPEnabled = network.DHCPEnabled, DNSDomain = network.DNSDomain, DNSHostName = network.DNSHostName, Index = Convert.ToInt32(network.Index), InterfaceIndex = Convert.ToInt32(network.InterfaceIndex) }; if (network.IPAddresses is string) { info.IPAddresses = new string[] { network.IPAddresses }; } else { object[] addresses = network.IPAddresses; info.IPAddresses = addresses.Cast <string>(); } if (network.IPSubnets is string) { info.IPSubnets = new string[] { network.IPSubnets }; } else { object[] subnets = network.IPSubnets; info.IPSubnets = subnets.Cast <string>(); } if (network.DefaultGateways != null) { if (network.DefaultGateways is string) { info.DefaultGateways = new string[] { network.DefaultGateways }; } else { object[] gateways = network.DefaultGateways; info.IPAddresses = gateways.Cast <string>(); } } server.GetServerInfo().Network.Add(info); } } }