Import CSV, Edit Data, Export CSV

Hello,
I am a powershell novice and have been given a task to complete. I need to scan through AD, find all of the servers that are supposed to be active, "ping" them and, if active, get their IP address and verify that a number of services are running.
Once all of the data is collected, I need to write all of this out to a .CSV file. So far, what I have is this:
Using Import-Module ActiveDirectory, I am able to get the full list of servers with appropriate information and export that to a CSV
I import the CSV file above back in and create new headers (columns) for more information
The full list of servers are pinged individually. If pingable, I get the IP address and service information needed
Where I am stuck is writing all of this back out to a .CSV file. Right now, I am just writing the information back out to the screen for verification. I'm sure it's something small, but being a novice I'm not sure where to go. Any help?

Here is the full code. The Write-Host statements are just for me during the testing to see if the information is correct. The last statement was what I tried to write the information out, but it came up empty and I really haven't found a way to get it to
work.
Import-Module ActiveDirectory    
Get-ADComputer -LDAPFilter "(OperatingSystem=*Server*)" -Property * |
    Select-Object Name,Created,LastLogonDate,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,CanonicalName |
    ? {$_.CanonicalName -notlike "*Archived Servers*" -and $_.CanonicalName -notlike "*Sun Prod*"} |
    Export-CSV "c:\temp\AllADComputers4.CSV" -NoTypeInformation -Encoding UTF8
#Add other headers
$csv = get-content "c:\temp\AllADComputers4.CSV"
$csv[0] += ",Pingable,IPAddress,SCCM Status,AV Name,AV Version,AV Status"
$csv | out-file "c:\temp\AllADComputers4.CSV"
$MachineInfo = Import-Csv -Path "c:\temp\AllADComputers4.CSV"
$Processed = ForEach ($objitem in $MachineInfo)
    If (Test-Connection -ComputerName $Objitem.Name -Quiet -Count 1)
        If (Get-Service -name "Symantec AntiVirus" -computername $Objitem.Name)
            $AVStatus = Get-Service -name "Symantec AntiVirus" -computername $Objitem.Name
            $AVName = "Symantec AntiVirus"
        Elseif (Get-Service -name SepMasterService -computername $Objitem.Name)
            $AVStatus = Get-Service -name SepMasterService -computername $Objitem.Name
            $AVName = SepMasterService
        ElseIf (Get-Service -name "Norton AntiVirus Server" -computername $Objitem.Name)
            $AVStatus = Get-Service -name "Norton AntiVirus Server"-computername $Objitem.Name
            $AVName = "Norton AntiVirus Server"
        Else
            $AVStatus = "Stopped"
            $AVName = "None"
        $SCCMAgentStatus = Get-Service -name ccmexec -computername $Objitem.Name
        $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Objitem.Name | ? {$_.IPEnabled}
        $objitem.Pingable = "Yes"
        foreach ($Network in $Networks)
                $IPAddress  = $Network.IpAddress[0]
        Write-Host $Objitem.Name,"...Success...",$IPAddress,"   SCCM Status = ",$SCCMAgentStatus.Status, "Anti-Virus = ",$AVName, "Status = ",$AVStatus.Status
        $service = gwmi -computername $objItem.Name -class Win32_Service | ? {$_.Name -eq $AVName}
        $path = ($service | Select -Expand PathName)
        $path = $path.Replace(":","$")
        $path = $path.Replace('"','')
        $FullPath = "\\"+$objitem.Name+"\"+$path
        $ver = Get-ItemProperty -Path $FullPath | select-object -expand VersionInfo | select-object -expand ProductVersion
        Write-Host $Fullpath
        Write-Host "Version = ",$ver
    Else
        Write-Host $Objitem.Name"...Failed"
        $objitem.Pingable = "No"
$Processed | export-csv -Path "c:\temp\AllADProcessed.CSV"

Similar Messages

  • Import 320x240, edit, then export 320x240?

    Can I work in 320x240 format native in FCE? I have a bunch of pre-existing video that I need to piece together and then export but I can only do 720x480.

    FCE will only edit DV or HDV material. Any other material has to be scaled up to fit that size, and then scaled back down. You probably don't want to do that.

  • "Data only" csv export. How to get the same data?

    When I export to csv I get more data than when exporting to "data only". Why and how to get the same as when using "data only". I suppose it is because of some supressed lines, but why there is difference in the view (which is right) and in the export file?
    I do not want to export to xls with "data only" and save as csv, because the exported csv is being read by another application, which is unable to convert it automatically.
    The other way is to put constraints in the data selection for the whole report (and not by supressing lines). How to say {table.date}>=maximum({table.date}) in the  in the data selection? There is not possible to use "maximum". Probably possible with array?
    Thanks in advance
    Edited by: Kiril Bojilov on Aug 4, 2009 12:34 PM
    Ok, I managed it: I put the constraint in the group selection
    Edited by: Kiril Bojilov on Aug 4, 2009 12:46 PM

    New customers get more options because new customers didn't already agree to complete a 2yr contract before being able to get a new phone. If you had a line that wasn't under contract, you would get a better deal than new customers because while they pay $35 activation fee for a new line, you pay $30 upgrade fee for using an upgrade. You just have to finish your end of the deal before you can start a new one.

  • Export-CSV as a different user

    Wrote a sript to audit a few reg keys and other vitals from the computer.  Eventually I will have this go to a database but in the meantime I am trying to write it to a text file.  These are mobile computers that log in as a generic local user.
    The powershell script as is needs to write to a domain file and therefore doesnt have permissions.  Can someone help me use different creds within the powershell script to use for access?
    The Export-CSV function is in use for the append switch as these are powershell v2
    #Get Local User SID for use as primary key
    $CS = Gwmi Win32_ComputerSystem -Comp "."
    $CS.UserName
    $objUser = New-Object System.Security.Principal.NTAccount($CS.UserName)
    $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
    #$strSID.value
    #Get Versions
    $SoftwareVersionKey = 'HKLM:\SOFTWARE\Wow6432Node\Software1\Portal'
    $SoftwarePackageVersion = (Get-ItemProperty -path $Software1VersionKey).VERSION1
    $Software1Version = (Get-ItemProperty -path $Software1VersionKey).Version1
    #$Software1PackageVersion
    #$Software1Version
    #Get Software1 GUID
    $Software1Key = 'HKLM:\SOFTWARE\Wow6432Node\Software1'
    $Software1GUID = (Get-ItemProperty -path $Software1Key).GUID
    #$Software1GUID
    #Get Software1 Datasync Identity
    $Software1DSIdentKey = 'HKLM:\SOFTWARE\Wow6432Node\Software1\SyncAgent'
    $Software1Identity = (Get-ItemProperty -path $Software1DSIdentKey).Identity
    #$Software1Identity
    #Get Computer Information / Computer Name / Installed Memory (MB)
    $WMI = Get-WmiObject -Class Win32_ComputerSystem
    $computername = ($WMI.name)
    $computerDomain = ($WMI.Domain)
    $computerManufacturer = ($WMI.Manufacturer)
    $computerModel = ($WMI.Model)
    $InstalledMemory = ($WMI.TotalPhysicalMemory/1mb)
    #Get Computer Information / Computer Name / Installed Memory (MB)
    $WMIBIOS = Get-WmiObject -Class Win32_BIOS
    $BIOSVersion1 = ($WMIBIOS.SMBIOSBIOSVersion)
    $BIOSVersion2 = ($WMIBIOS.Version)
    $computerSerial = ($WMIBIOS.SerialNumber)
    #Date
    $date = Get-Date -format "yyyyMMdd"
    function Export-CSV {
    [CmdletBinding(DefaultParameterSetName='Delimiter',
    SupportsShouldProcess=$true, ConfirmImpact='Medium')]
    param(
    [Parameter(Mandatory=$true, ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
    [System.Management.Automation.PSObject]
    ${InputObject},
    [Parameter(Mandatory=$true, Position=0)]
    [Alias('PSPath')]
    [System.String]
    ${Path},
    [Switch]
    ${Append},
    [Switch]
    ${Force},
    [Switch]
    ${NoClobber},
    [ValidateSet('Unicode','UTF7','UTF8','ASCII','UTF32',
    'BigEndianUnicode','Default','OEM')]
    [System.String]
    ${Encoding},
    [Parameter(ParameterSetName='Delimiter', Position=1)]
    [ValidateNotNull()]
    [System.Char]
    ${Delimiter},
    [Parameter(ParameterSetName='UseCulture')]
    [Switch]
    ${UseCulture},
    [Alias('NTI')]
    [Switch]
    ${NoTypeInformation})
    begin
    $AppendMode = $false
    try {
    $outBuffer = $null
    if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
    $PSBoundParameters['OutBuffer'] = 1
    $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Export-Csv',
    [System.Management.Automation.CommandTypes]::Cmdlet)
    $scriptCmdPipeline = ''
    if ($Append) {
    $PSBoundParameters.Remove('Append') | Out-Null
    if ($Path) {
    if (Test-Path $Path) {
    $AppendMode = $true
    if ($Encoding.Length -eq 0) {
    $Encoding = 'ASCII'
    $scriptCmdPipeline += 'ConvertTo-Csv -NoTypeInformation '
    if ( $UseCulture ) {
    $scriptCmdPipeline += ' -UseCulture '
    if ( $Delimiter ) {
    $scriptCmdPipeline += " -Delimiter '$Delimiter' "
    $scriptCmdPipeline += ' | Foreach-Object {$start=$true}'
    $scriptCmdPipeline += '{if ($start) {$start=$false} else {$_}} '
    $scriptCmdPipeline += " | Out-File -FilePath '$Path'"
    $scriptCmdPipeline += " -Encoding '$Encoding' -Append "
    if ($Force) {
    $scriptCmdPipeline += ' -Force'
    if ($NoClobber) {
    $scriptCmdPipeline += ' -NoClobber'
    $scriptCmd = {& $wrappedCmd @PSBoundParameters }
    if ( $AppendMode ) {
    $scriptCmd = $ExecutionContext.InvokeCommand.NewScriptBlock(
    $scriptCmdPipeline
    } else {
    $scriptCmd = $ExecutionContext.InvokeCommand.NewScriptBlock(
    [string]$scriptCmd
    $steppablePipeline = $scriptCmd.GetSteppablePipeline(
    $myInvocation.CommandOrigin)
    $steppablePipeline.Begin($PSCmdlet)
    } catch {
    throw
    process
    try {
    $steppablePipeline.Process($_)
    } catch {
    throw
    end
    try {
    $steppablePipeline.End()
    } catch {
    throw
    New-Object -TypeName PSCustomObject -Property @{
    UserSID = $strSID.value
    ComputerName = $computername
    Domain = $computerDomain
    ComputerManufactor = $computerManufacturer
    ComputerModel = $computerModel
    ComputerSerial = $computerSerial
    InstallMemory = $InstalledMemory
    BIOS1 = $BIOSVersion1
    BIOS2 = $BIOSVersion2
    Software1PackageVersion = $Software1PackageVersion
    Software1Version = $Software1Version
    Software1GUID = $Software1GUID
    Software1Identity = $Software1Identity
    Date = $date
    } | Export-Csv -Path '\\server\drive\IT Shared\Audittest.csv' -NoTypeInformation -Append

    To shorten this code up a little...  really here is the last part that I am trying to do.  Just want to send variable data to text file but cant due to logged in user.
    New-Object -TypeName PSCustomObject -Property @{
    UserSID = $strSID.value
    ComputerName = $computername
    Domain = $computerDomain
    ComputerManufactor = $computerManufacturer
    ComputerModel = $computerModel
    ComputerSerial = $computerSerial
    InstallMemory = $InstalledMemory
    BIOS1 = $BIOSVersion1
    BIOS2 = $BIOSVersion2
    Software1PackageVersion = $Software1PackageVersion
    Software1Version = $Software1Version
    Software1GUID = $Software1GUID
    Software1Identity = $Software1Identity
    Date = $date
    } | Export-Csv -Path '\\server\drive\IT Shared\Audittest.csv' -NoTypeInformation -Append

  • Append multiple wmi queries export csv

    Hello I am trying to query wmi data and export it to a csv, how ever I cant seem to get multiple wmi data to append to the same file. I don't know why you cant chain the command.
    $computers = Get-Content -Path C:\machines.txt
    $computers = $computers.Trim()
    $test = Get-WmiObject win32_Bios -cn $computers | Select-Object Description,SerialNumber
    $test2 = Get-WmiObject Win32_Computersystem -cn $computers | Select-Object Domain,Manufacturer,Model,Name,NumberOfProcessors
    $test2 | Export-CSV -Path "C:\Users\Public\outputfile.csv" -notypeinformation
    $test | Export-CSV -Path "C:\Users\Public\outputfile.csv" -append -Force
    Thank you for you help.

    Hi,
    The best way to do something like this is to build yourself a custom object with this data. Here's how I'd go about doing something like this:
    (Get-Content .\computerList.txt).Trim() | ForEach {
    If (Test-Connection -ComputerName $_ -Count 1 -Quiet) {
    $bios = Get-WmiObject Win32_BIOS -ComputerName $_
    $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_
    $props = @{
    ComputerName = $_
    Description = $bios.Description
    SerialNumber = $bios.SerialNumber
    Domain = $cs.Domain
    Manufacturer = $cs.Manufacturer
    Model = $cs.Model
    Name = $cs.Name
    NumberOfProcessors = $cs.NumberOfProcessors
    New-Object PsObject -Property $props
    } Else {
    Write-Warning "$_ cannot be reached, skipping."
    } | Sort ComputerName |
    Select ComputerName,Description,SerialNumber,Domain,Manufacturer,Model,Name,NumberOfProcessors |
    Export-Csv .\computerDetails.csv -NoTypeInformation
    Don't retire TechNet! -
    (Don't give up yet - 12,950+ strong and growing)

  • Import Meta Data from CSV - Export Meta Data to CSV

    Ability to import meta data into selected images from CSV file containing a number of fields, one of which is file name. The other fields would be selected tags to import.
    Import logic would be, Where file name in column 1 matches current selected filename, then take following fields 2, 3, etc and import into Bridge.
    Export selected meta data from selected files to CSV to form reverse of above to allow edit of data in Excel etc.
    Further enchancement on import would be to allow instead of just filename, but date/time range matching.
    Logic would be, Where date/time in column 1 is within X hours of selected
    image creation date/time then import following fields into image meta data.
    Useful for example if you already have a GPS tracklog in CSV and want to try and update images with GPS. Assuming camera clock approx same as GPS clock.

    The issue was within the .csv file.  There were duplicate records that were attempting to load as the ID value.  After deleting the duplicate records, the transformation file ran successfully.
    Debbie

  • How to import data from CSV file with columns separated by semicolon?

    I migrate database from MS SQL 2008 to ORACLE 11g
    I export data to CSV file from MS SQL
    then I try to import it to Oracle
    several tables goes fine using Import data option in the SQL Developer
    Standard CSV files with data separated by comma were imported.
    chars, date (with format string), and integer data are imported via import wizard without problems
    the problems were when I try to import table with noninteger numbers with modal part separated by comma not by dot
    comma is the standard separator for columns in CSV file
    so I must change the standard separator to semicolon
    then the import wizard have problem to correct recognize the columns data because it use only standard CSV comma separator :-/
    In SQL Developer 1.5.3 Tools -> Preferences -> Migration -> Data Move Options
    I change "End of Column Delimiter" to ; but it doens't work
    Is this possible to change the standard column separator for import data wizzard in SQL Developer 1.5.3?
    Or maybe someone know how to import data in SQL Developer 1.5.3 from CSV when CSV colunn separator is set to semicolon?

    A new preference has been added to customize the import delimiter in main code line. This should be available as part of future release.

  • W520 - Lenovo Password Manager - Can .CSV or .DAT files be imported from other Password Managers?

    The title says it all!
    Currently using Norton Identity Safe's standalone password manager, but would like to start using Lenovo's instead. Attempted to import .DAT and/or .CSV files from Norton, but no option for these file types appeared in Lenovo's Password Manager.
    If not an option to import directly, is it possible to add one of the files to the location Lenovo stores the password manger entries?
    Solved!
    Go to Solution.

    Hello, 
    No you can't import .CSV or .DAT files into Password Manager. It uses a .PWM file format, and uses a 256-bit key Advanced
    Encryption Standard (AES) with Microsoft CryptoAPI. You can export your info to be used in another machine with the Thinkvantage Password Manager installed, but not from another password manager.
    More info here:
    Password Manager 4 Deployment Guide
    Cheers!
    ThinkPad W540 (20BG) - i7-4800MQ/24GB // ThinkPad T440s (20AQ) - i7-4600U/12GB
    ThinkPad T440p (20AW) - i7-4800MQ/16GB // ThinkPad Helix (3698-6EU) - i5-3337U/4GB
    ThinkPad W520 (4282-W4Q) - i7-2720QM/32GB // ThinkPad T400 (2767-W1C) - P9500/8GB
    ThinkPad T61 (7665-CTO) - T7700/4GB // ThinkPad T60p (8741-C2G) - T7400/4GB

  • Automatic import of material data (csv file) from FTP directory

    Hello Experts,
    We created a Scheduled Task -> Data Import Monitor -> from a FTP directory.
    We loaded the .csv file with material data in the FTP folder but it is not getting imported.We have created the .csv file with the format of fields defined in Company quick start Work book -> Material tab. We also tried with a .csv file having first Field as CLASS_NAME with a value of masterdata.Material and rest of the fields same as defined in the Company quick start-Materials Tab still it did not work.
    When we load the .xls work book in FTP directory (xl having the Configuration tab and Material tab) the data import is working fine and the data is getting loaded automatically from the data import monitor job.
    Is there any specific format of .csv file in which the material data needs to be loaded to the FTP server for automatic import of data using Scheduled task?
    Regards
    Aditya

    Are there any errors appearing in the FPA logs?
    Have you checked the permissions on the folder/file that you are uploading from?
    What type of scheduled task have you created?

  • Import-csv and export-csv

     Hi everyone,
    How do I modify the script so that I see all the entries in the computers_result.csv file.  As it stands only the last entry in the computers.csv shoes up in the computers_result.csv file.  Thanks so much.
    Import-Csv C:\computers.csv | ForEach-Object {
    $computername = $_.computer
    $result = get-adcomputer $computername -Properties description  | select Name,Description
    $result | export-csv C:\computers_result.csv

    Try this and let me know
    $result = @()
    Import-Csv C:\computers.csv | ForEach-Object {
    $computername = $_.computer
    $result += get-adcomputer $computername -Properties description | select Name,Description
    $result | export-csv C:\computers_result.csv
    Regards Chen V [MCTS SharePoint 2010]

  • Import data from csv to SQL database

    How to  Import data from csv to SQL database through BLS-xMII?

    Hi,
    if you using Oracle, you may also use the bulk insert with MII. You can use the String List to XML parser to convert your CSV to XML, and then use a query that calls a stored procedure which does the bulk insert.
    Also have a look at thread [read XML file into stored procedure|http://forums.sdn.sap.com/click.jspa?searchID=63850236&messageID=7455643].
    Michael

  • Get-Mailbox PS command import/export csv - need help

    Greetings,
    I know this should be simple but I'm having trouble.  I have about 500 users that have left the company and I want to verify their Exchange 2010 mailbox have been disabled.  If I just run the basic command "Get-Mailbox -identity alias"
    I see all I need to see.  The Name, Alias, and ServerName (that their mailbox is on).  If I check someone whose mailbox has been disabled I get "object could not be found."  Perfect, then I know their mailbox no longer exists. 
    In trying to import a csv file of the 500 users - and export it I'm having trouble. There are a few posts on these forums for similar issues but none are working or the conditions are different.  I'm not too good and PS scripting so I am hoping someone
    can assist.  I pieced this together.
    import-csv C:\temp\DisabledMBs.csv | get-mailbox >c:\temp\DisabledMBsOutput.csv
    The csv output file is blank.  The PS screen outputs this error for each user.
    The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
        + CategoryInfo          : InvalidArgument: (@{Name=Heaton; ...er Logon Name=}:PSObject) [Get-Mailbox], ParameterBindingException
        + FullyQualifiedErrorId : InputObjectNotBound,Get-Mailbox
    I guess I'm missing something here but stuck.  Any help is greatly appreciated!
    thank you!

    If you use a CSV for input, you need to tell the Get-Mailbox command what field is the identifier.  So if you have an alias field in your CSV, you would run your command as follows:
    import-csv C:\temp\DisabledMBs.csv | % { get-mailbox $_.Alias } | Export-Csv c:\temp\DisabledMBsOutput.csv -NoTypeInformation
    BTW, you'll notice that I've also piped your output to the Export-Csv command.  If you just pipe the output of Get-Mailbox to a file with a CSV suffix, you don't get a CSV - you get a text file with only one field named "Name                     
    Alias                ServerName       ProhibitSendQuota" (note, not "Name", "Alias", "ServerName", and "ProhibitSendQuota"
    separately).

  • Export Data as CSV - PHP/MySQL

    Hi, is it possible to export MySQL data as CSV using developer toolbox? My PHP knowledge is very basic so please be gentle.
    Thanks
    Bert

    Hi Bert,
    no, ADDT doesn´t provide this feature, but there are quite some other extensions out there to export results from a recordset as CSV -- guess you´ll find some listed in the Dreamweaver Exchange.
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • Export batch data into CSV file using SQL SP

    Hi,
    I have created WCF-Custom receive adapter to poll Sql SP (WITH xmlnamespaces(DEFAULT 'Namespace' and For XML PATH(''), Type) . Get the result properly in batch while polling and but getting error while converting into CSV by using map.
    Please can anyone give me some idea to export SQL data into CSV file using SP.

    How are you doing this.
    You would have got XML representation for the XML batch received from SQL
    You should have a flat-file schema representing the CSV file which you want to send.
    Map the received XML representation of data from SQL to flat-file schema
    have custom pipeline with flat-file assembler on the assembler stage of the send pipeline.
    In the send port use the map which convert received XML from SQL to flat file schema and use the above custom flat-file disassembler send port
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Error - During Export Grid Data to CSV

    OS: Windows XP
    Detail: Eror Message Pop-Up During Export Grid Data to CSV. Error Message:
    ORA-00972: identifier is too long
    Vendor code 972.

    There is a bug with all export formats if you are exporting without using aliases and you export a long text string (see More export issues/bugs
    This will fail:
    select 'testing query execution on export' from dual
    This will work:
    select 'testing query execution on export' dummy from dual

Maybe you are looking for