# Get computer system information
$computerSystem = Get-WmiObject -Class Win32_ComputerSystem
# Get BIOS information for the computer serial number
$biosInfo = Get-WmiObject -Class Win32_BIOS
# Get CPU information
$cpuInfo = Get-WmiObject Win32_Processor
# Define CPU architecture mapping
$cpuArchitecture = switch ($cpuInfo.Architecture) {
0 { "x86" }
1 { "MIPS" }
2 { "Alpha" }
3 { "PowerPC" }
5 { "ARM" }
6 { "ia64" }
9 { "x64" }
default { "Unknown" }
}
# Get operating system information
$operatingSystem = Get-WmiObject -Class Win32_OperatingSystem
# Get hard disk information
$diskInfo = Get-WmiObject Win32_DiskDrive
# Get partition information
$partitionInfo = Get-WmiObject Win32_LogicalDisk
# Get RAM information
$ramInfo = Get-WmiObject Win32_PhysicalMemory
# Get keyboard information
$keyboardInfo = Get-WmiObject Win32_Keyboard
# Get mouse information
$mouseInfo = Get-WmiObject Win32_PointingDevice
# Get the current date and time
$timestamp = Get-Date
# Format the timestamp
$timestampFormatted = $timestamp.ToString("yyyy-MM-dd HH:mm:ss")
# Get monitor details
$monitorDetails = Get-WmiObject -Namespace root\wmi -Class WmiMonitorID
# Create an array to store monitor details
$monitorList = @()
# Populate monitor details
foreach ($monitor in $monitorDetails) {
$Manufacturer = [System.Text.Encoding]::ASCII.GetString(($monitor.ManufacturerName | Where-Object {$_ -ne 0}))
$SerialNumber = [System.Text.Encoding]::ASCII.GetString(($monitor.SerialNumberID | Where-Object {$_ -ne 0}))
$Model = [System.Text.Encoding]::ASCII.GetString(($monitor.UserFriendlyName | Where-Object {$_ -ne 0}))
$monitorList += [PSCustomObject]@{
Manufacturer = $Manufacturer
Model = $Model
SerialNumber = $SerialNumber
}
}
# Get currently logged-in user
$loggedUser = $computerSystem.UserName
# Get domain joined details
$domainJoinedDetails = $computerSystem
# Get members of the local Administrators group
$adminMembers = Get-LocalGroupMember -Group "Administrators" | Select-Object -ExpandProperty Name
$adminMembersString = $adminMembers -join ";"
# Get the last update date
$lastUpdateDate = $operatingSystem.LastBootUpTime
# Get details about the last patch installed
$lastPatch = Get-HotFix | Sort-Object -Property InstalledOn -Descending | Select-Object -First 1
# Get the public IP address using an external service
$publicIP = Invoke-RestMethod -Uri "https://api.ipify.org" -UseBasicParsing
# Get private IP address
$privateIP = (Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress }).IPAddress[0]
# Combine all disk and partition details into single properties
$diskModels = ($diskInfo | ForEach-Object { $_.Model }) -join ";"
$diskSizes = ($diskInfo | ForEach-Object { [math]::Round($_.Size / 1GB, 2) }) -join ";"
$diskSerialNumbers = ($diskInfo | ForEach-Object { $_.SerialNumber }) -join ";"
$diskInterfaceTypes = ($diskInfo | ForEach-Object { $_.InterfaceType }) -join ";"
$driveLetters = ($partitionInfo | ForEach-Object { $_.DeviceID }) -join ";"
$volumeNames = ($partitionInfo | ForEach-Object { $_.VolumeName }) -join ";"
$fileSystems = ($partitionInfo | ForEach-Object { $_.FileSystem }) -join ";"
$freeSpaces = ($partitionInfo | ForEach-Object { [math]::Round($_.FreeSpace / 1GB, 2) }) -join ";"
$totalSizes = ($partitionInfo | ForEach-Object { [math]::Round($_.Size / 1GB, 2) }) -join ";"
# Combine all RAM details into single properties
$ramCapacities = ($ramInfo | ForEach-Object { [math]::Round($_.Capacity / 1GB, 2) }) -join ";"
$ramManufacturers = ($ramInfo | ForEach-Object { $_.Manufacturer }) -join ";"
$ramSpeeds = ($ramInfo | ForEach-Object { $_.Speed }) -join ";"
$ramSerialNumbers = ($ramInfo | ForEach-Object { $_.SerialNumber }) -join ";"
# Create a single object with all details
$computerDetails = [PSCustomObject]@{
ComputerName = $computerSystem.Name
Manufacturer = $computerSystem.Manufacturer
Model = $computerSystem.Model
ComputerSerialNumber = $biosInfo.SerialNumber
SystemType = $computerSystem.SystemType
OperatingSystem = $operatingSystem.Caption
OSVersion = $operatingSystem.Version
OSBuildNumber = $operatingSystem.BuildNumber
RegisteredUser = $operatingSystem.RegisteredUser
CPUManufacturer = $cpuInfo.Manufacturer
CPUModel = $cpuInfo.Name
CPUSerialNumber = $cpuInfo.ProcessorId
CPUArchitecture = $cpuArchitecture
NumberOfCores = $cpuInfo.NumberOfCores
NumberOfLogicalProcessors = $cpuInfo.NumberOfLogicalProcessors
DiskModels = $diskModels
DiskSizesGB = $diskSizes
DiskSerialNumbers = $diskSerialNumbers
DiskInterfaceTypes = $diskInterfaceTypes
DriveLetters = $driveLetters
VolumeNames = $volumeNames
FileSystems = $fileSystems
FreeSpacesGB = $freeSpaces
TotalSizesGB = $totalSizes
RAMCapacitiesGB = $ramCapacities
RAMManufacturers = $ramManufacturers
RAMSpeedsMHz = $ramSpeeds
RAMSerialNumbers = $ramSerialNumbers
KeyboardDescription = $keyboardInfo.Description -join ";"
KeyboardDeviceID = $keyboardInfo.DeviceID -join ";"
MouseDescription = $mouseInfo.Description -join ";"
MouseDeviceID = $mouseInfo.DeviceID -join ";"
MonitorManufacturer = ($monitorList | Select-Object -ExpandProperty Manufacturer) -join ";"
MonitorModel = ($monitorList | Select-Object -ExpandProperty Model) -join ";"
MonitorSerialNumber = ($monitorList | Select-Object -ExpandProperty SerialNumber) -join ";"
LoggedInUser = $loggedUser
Domain = $domainJoinedDetails.Domain
DomainJoined = $domainJoinedDetails.PartOfDomain
AdminGroupMembers = $adminMembersString
LastUpdateDate = $lastUpdateDate
LastPatchKBNumber = $lastPatch.HotFixID
LastPatchDescription = $lastPatch.Description
LastPatchInstalledOn = $lastPatch.InstalledOn
PublicIP = $publicIP
PrivateIP = $privateIP
Timestamp = $timestampFormatted
}
# Define the folder path
$folderPath = "C:\System"
# Create the folder
New-Item -ItemType Directory -Path $folderPath -Force
# Export to CSV
$computerDetails | Export-Csv -Path "C:\System\ComputerDetails.csv" -NoTypeInformation
# Define variables
$ftpServer = ""
$ftpUsername = ""
$ftpPassword = ""
$localFilePath = "C:\System\ComputerDetails.csv" # Local path of the CSV file to upload
$remoteFileName = "ComputerDetails.csv" # Name of the file on the FTP server
$tempFilePath = "C:\System\TempComputerDetails.csv" # Temporary path to store the downloaded file
# Create the full FTP path
$ftpUri = "$ftpServer/$remoteFileName"
# Create a WebClient object
$webClient = New-Object System.Net.WebClient
# Set the credentials
$webClient.Credentials = New-Object System.Net.NetworkCredential($ftpUsername, $ftpPassword)
try {
# Download the existing CSV file from the FTP server
$webClient.DownloadFile($ftpUri, $tempFilePath)
Write-Output "Downloaded existing CSV file from FTP server."
# Get the content of the local CSV file
$newData = Get-Content $localFilePath
# Remove the title row from the new data
$newData = $newData | Select-Object -Skip 1
# Append the new data to the existing file
Add-Content -Path $tempFilePath -Value $newData
Write-Output "Appended new data to the existing CSV file."
# Upload the updated CSV file back to the FTP server
$webClient.UploadFile($ftpUri, $tempFilePath)
Write-Output "Uploaded the updated CSV file to FTP server at '$ftpUri'."
} catch [System.Net.WebException] {
# Handle specific FTP errors
Write-Error "Failed to download or upload the CSV file. Error: $($_.Exception.Message)"
} catch {
Write-Error "Failed to process the CSV file. Error: $_"
} finally {
# Clean up the temporary file
if (Test-Path $tempFilePath) {
Remove-Item $tempFilePath -Force
}
# Dispose the WebClient object
$webClient.Dispose()
}
Change FTP Server, FTP username, FTP Password