Hi all!
Im writing a script that will connect to a series of remote computers and retrive hardware and software info such as CPU, RAM size, HDD size etc and have that info exported to seperate CSV files.
The Name or IP Adresses, usernames and passwords of the remote computers are imported into PS via another CSV file at the start of the script.
The problem im having is that i want every single exported CSV file to contain a column "Computername" so i can easily see what details belong to which computer, most of the Get-wmiobject i run have this property but " Get-WmiObject Win32_OperatingSystem"
for example does not.
Is there a simple way to append this detail to each seperate CSV file? I tried pulling the computernames from the imported CSV file and then have it append to the exported ones but i cant get it to work.
Below is my code, its not finished yet but has enough code for you to hopefully get an idea of what im trying to do :)
Clear-Host $Import = Import-Csv -Path 'C:\Users\Notumlord\Documents\PowerShell\Imp.csv' $Import | ForEach { $ComputerName = $import.ComputerName $UserName = $Import.UserName $PassWord = $Import.Password } $i=0 $placefolder = 'C:\Users\Notumlord\Documents\PowerShell\Resultat'
$Folderplace =New-Item -Path $placefolder -ItemType Directory -Name ("System_results.$(Get-date -f "yyyy-MM_dd_HHmmss")") $Hardware =New-Item -Path $Folderplace -ItemType Directory -Name ("Hardware") $Bios = New-Item -Path $Folderplace -ItemType File -name ("Bios_Results.csv") $DiskSize = New-Item -Path $Folderplace -ItemType File -name ("DiskSize_Results.csv") $Operativsystem = New-Item -Path $Folderplace -ItemType File -name ("Operativsystem_Results.csv") $OsPatcher = New-Item -Path $Folderplace -ItemType File -name ("OSPatcher_Results.csv") $Mjukvara = New-Item -Path $Folderplace -ItemType File -name ("Mjukvara_Results.csv") $IPConfig = New-Item -Path $Folderplace -ItemType File -name ("IPConfig_Resultat.csv") $Ram = New-Item -Path $Hardware -ItemType File -name ("Ram_Resultat.csv") $HDD = New-Item -Path $Hardware -ItemType File -name ("Hårddiskar_Resultat.csv") $CPU = New-Item -Path $Hardware -ItemType File -name ("Processor_Resultat.csv") $MB = New-Item -Path $Hardware -ItemType File -name ("Moderkort_Resultat.csv") $Import | Foreach { $SecPassword = ConvertTo-SecureString $PassWord[$i] -AsPlainText -Force $Credentials = New-Object System.Management.Automation.PSCredential ($UserName[$i],$SecPassword) $namn = Get-WmiObject -Class Win32_Computersystem | Select-Object Name $datornamn=$namn[0].name.ToString() Get-WmiObject "win32_BIOS" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object Name,Description,Status,Version ` | Export-CSV -Path $Bios -Append -Force -NoTypeInformation Get-WmiObject "win32_diskdrive" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object PScomputername,Size,Status ` | Export-CSV -Path "$DiskSize" -Append -Force -NoTypeInformation Get-WmiObject "Win32_OperatingSystem" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | select-object ServicePackMajorVersion ` | Export-CSV -Path $OsPatcher -Append -Force -NoTypeInformation Get-WmiObject "Win32_OperatingSystem" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object Caption ` | Export-CSV -Path $Operativsystem -Append -Force -NoTypeInformation Get-WmiObject "Win32_NetworkAdapterConfiguration" -Filter “IpEnabled=$true” -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object -property @{N="IPAddress";E={$_.IPAddress -join ';'}}, PSComputerName, Description, DHCPServer ` | Export-CSV -Path $IPConfig -Append -Force -NoTypeInformation Get-WmiObject "Win32_PhysicalMemory" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object Type,Manufacture,Speed,Formfactor,Capacity ` | Export-CSV -Path $Ram -Append -Force -NoTypeInformation Get-WmiObject "Win32_LogicalDisk" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object DriverID,Drivertype,Freespace,Size ` | Export-CSV -Path $HDD -Append -Force -NoTypeInformation Get-WmiObject "CIM_Processor" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object Name,DeviceID,Maxclockspeed,SocketDesignation ` | Export-CSV -Path $CPU -Append -Force -NoTypeInformation Get-WmiObject "Win32_BaseBoard" -ComputerName $ComputerName[$i] -Credential $Credentials[$i] | Select-Object Name,Manufacture,Product,Serialnumber ` | Export-CSV -Path $MB -Append -Force -NoTypeInformation $i++ }
Any help would be greatly appriceated!