Hello All,
I need power shell script to validate entire server information to extract data stored in .xls, .html format.
Need to extract complete details in that server exist example : All folders names and sizes and drives ,Com components if it register in that server et.
All server information extract in the single file .

Abhishek YadavRank #217 · 11.3K reputationPosted Aug 29, 2023, 2:16 AM EDT
Here's a PowerShell script that validates the entire server information and extracts data stored in .xls and .html formats.
# Specify the server name $serverName = "servername" # Specify the output file paths for .xls and .html $xlsOutputPath = "C:\path\to\output.xls" $htmlOutputPath = "C:\path\to\output.html" # Validate if the server is reachable $pingResult = Test-Connection -ComputerName $serverName -Count 1 -Quiet if ($pingResult) { Write-Host "Server is reachable." # Validate if .xls files exist $xlsFiles = Get-ChildItem -Path "\\$serverName\path\to\files" -Filter "*.xls" -File -ErrorAction SilentlyContinue if ($xlsFiles) { Write-Host "Found $($xlsFiles.Count) .xls file(s)." # Extract data from .xls files # Modify this section according to your requirements to extract the specific data $xlsData = @() foreach ($file in $xlsFiles) { $data = Get-Content -Path $file.FullName $xlsData += $data } # Write .xls data to the output file $xlsData | Out-File -FilePath $xlsOutputPath Write-Host "Data from .xls file(s) is extracted and saved to $xlsOutputPath." } else { Write-Host "No .xls files found." } # Validate if .html files exist $htmlFiles = Get-ChildItem -Path "\\$serverName\path\to\files" -Filter "*.html" -File -ErrorAction SilentlyContinue if ($htmlFiles) { Write-Host "Found $($htmlFiles.Count) .html file(s)." # Extract data from .html files # Modify this section according to your requirements to extract the specific data $htmlData = @() foreach ($file in $htmlFiles) { $data = Get-Content -Path $file.FullName $htmlData += $data } # Write .html data to the output file $htmlData | Out-File -FilePath $htmlOutputPath Write-Host "Data from .html file(s) is extracted and saved to $htmlOutputPath." } else { Write-Host "No .html files found." } } else { Write-Host "Server is not reachable." }Make sure to update the
$serverName,$xlsOutputPath, and$htmlOutputPathvariables with your desired server name and output file paths.Please modify the data extraction sections (
# Modify this section according to your requirements to extract the specific data) of the script to extract the specific data you want from the .xls and .html files. The current script just reads the entire file content and adds it to the output.Also, update the file paths in the
Get-ChildItemcommands to match the actual file paths on the server where the .xls and .html files are located.Note: The script assumes that you have appropriate permissions and access rights to the server and the file locations.
Mohammad HussainRank #513 · 4.8K reputationPosted Aug 29, 2023, 3:54 AM EDT
# Install the ImportExcel module if not already installed Install-Module -Name ImportExcel -Force # Define the output Excel file path $outputPath = "C:\ServerInfo.xlsx" # Gather server information $serverInfo = @{ ServerName = $env:COMPUTERNAME OperatingSystem = (Get-WmiObject Win32_OperatingSystem).Caption CPU = (Get-WmiObject Win32_Processor).Name RAM = [math]::Round(((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory / 1GB), 2) Drives = (Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID, Size, FreeSpace) } # Export server information to Excel $serverInfo | Export-Excel -Path $outputPath -AutoSize -AutoSizeColumns Write-Host "Server information has been exported to $outputPath"