How to combine 3 PowerShell scripts to write results to CSV file?

Hello,
I have 3 domains, and I like to combine the results from the Get-ADUser and write the results into one CSV file.  Can this be done?  How to do this?  Below are the 3 Get-ADUser
scripts:
Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain1, DC=com" -Properties hiredate, department, surname, displayname  export-csv "d:\scripts\pbtfusers.csv"
Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain2, DC=com" -Properties hiredate, department, surname, displayname  export-csv
"d:\scripts\pbtfusers.csv"
Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain3, DC=com" -Properties hiredate, department, surname, displayname  export-csv
"d:\scripts\pbtfusers.csv"
Paul

Sure:
Get-ADUser tester1 | Export-Csv .\userOutput.csv
Get-ADUser tester2 | Export-Csv .\userOutput.csv -Append
Get-ADUser tester3 | Export-Csv .\userOutput.csv -Append
Sample output:
PS C:\Scripts\PowerShell Scripts\Misc Testing\9-3-2014> Import-Csv .\userOutput.csv | Select Name
Name
tester1
tester2
tester3
This is an extremely simplified example. It returns three user objects and writes them all to the output file one at a time.
Don't retire TechNet! -
(Don't give up yet - 13,085+ strong and growing)

Similar Messages

  • How to create power shell script to upload all termset csv files into the SharePoint2013 local taxonomy ?

    Hi Everyone,
    I want to create a powershell script file
    1) Check a directory and upload all termset csv files into the SharePoint local taxonomy.
    2) Input paramaters - directory that containss termset csv files, Local Termstore to import to,
    3) Prior to updating get a backup of the existing termstore (for rollback/recovery purposes)
    4) Parameters should be passed in via XML file.
    Please let me know how to do it.
    Regards,
    Srinivas

    Hi,
    Please check this link
    http://termsetimporter.codeplex.com/
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • How to change maintenance powershell script via GPO?

    Per suggestion reposted from here: http://social.technet.microsoft.com/Forums/windowsserver/en-US/6eece9d6-a524-48aa-8e64-7554f0ec9b31/how-to-change-maintenance-powershell-script-via-gpo?forum=winserverGP
    Posted at http://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/desktop-shortcuts-to-items-on-network-drives/94eddb27-342b-40fc-9ad4-677ff4ee8ebe?page=9&tm=1403700614489 originally.
    There is a very annoying "feature" in Windows 7 called BrokenShortcuts.ps1 which is being called out weekly via maintenance task and if it finds more than 4 "broken" network shortcuts it removes them all. So it means if a user at this
    moment is disconnected from the network he will lose all links to shares, network applications sitting on his desktop. Funny that there was no such script on Vista and i don't see this on Win8. On the post i have attached one user suggested to edit this script
    and change 4 to 500 or whatever high number. That's fine for one time fix. But i need to do this for 200+ users. This file cannot be simply replaced by a script, so i'm wondering is there any way to do it via GPO?
    I have already tried various startup scripts, but i'm not sure which user to put into commands.
    I need to run this on startup:
    takeown /F C:\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1
    icacls c:\windows\diagnostics\scheduled\maintenance\TS_BrokenShortcuts.ps1 /grant "some user":F
    copy \\share\folder$\TS_BrokenShortcuts.ps1 C:\Windows\diagnostics\scheduled\Maintenance\ /Y

    You need to take time to study how Windows does these things.  You can control them with GP which is what you asked.  The article shows you how to disable elements of the tasks.  Each task controls a script.  If you disable the task the
    script that deletes shortcuts will be stopped. Other maintenance tasks will continue to run.
    Most of your problem is that you seem to want someone to provide a magical solution.  In technology it is necessary to fully research your issues until you understand all aspects.  After fully studying the issue you should understand the possible
    solutions if they exist.
    You claim to have deployed the patch that Microsoft released to fix the issue.  You claim it didn't work.  If that is the case then you need to call MS and \p[en a support incident.  If  Microsoft determines that you are right about the
    patch not working you will not be charged for the call.
    I know that learning how to support technology is hard and frustrating for newcomers.  In time, by using these incidents to learn, you will become a seasoned technician and all of this will seem trivial.  Until then we can only suggest that you
    do things that most of us are familiar with.  We cannot fix your network for you.
    I think you haven't really posted in the GP forum but posted a question about GP in the server forum.  Try posting in the GP forum.
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverGP
    Here is one answer from the GP forum:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverGP
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/600ca14f-8b1b-400c-b27f-a7f5733407ac/windows-scheduled-maintenance-task?forum=winserverGP
    ¯\_(ツ)_/¯

  • How to sign a powershell script to be used for distribution

    Hi,
    I am new to powershell so if I'm missing out on any detail, please let me know.
    We have some powershell scripts we send over to the clients to execute. Their powershell enviroment has execution policy set to 'remote signed'
    Now I have read multiple blogs for how to sign the powershell script to be used at different execution levels, but my understanding is signing is for my environment only.
    http://www.hanselman.com/blog/SigningPowerShellScripts.aspx
    http://blogs.technet.com/b/heyscriptingguy/archive/2010/06/17/hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-2-of-2.aspx
    I'm probably missing out on something obvious and I'll appreciate if someone can explain me how to sign my script so that client can use it in their environment with any execution level set.
    Thanks in advance!

    Here's a bit more information on the subject:
    http://technet.microsoft.com/en-us/library/hh847874.aspx
    http://msdn.microsoft.com/en-us/library/ms537361.aspx
    You can get code signing certificates from the major vendors.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Scheduled task powershell script cant write file

    Hello experts
    I have scheduled task with powershell but cant write CSV file. Below my PS script:
    $ExemptGroup = Get-ADGroup app_users
    Get-ADUser -Filter { -not (memberOf -RecursiveMatch $ExemptGroup.DistinguishedName) } -Properties * |
     Select-Object -Property DisplayName,SamAccountName,WhenCreated,@{Name='Last Logon';Expression={[System.DateTime]::FromFileTime($_.LastLogon).ToString('g')}},LogonCount,@{N='Status';E={
    If ( $_.useraccountControl -match '^(?:514|546|66050|66082)$' ) { 'Disabled' } Else { 'Enabled' } }} |
     Sort-Object -Property DisplayName | Export-Csv C:\Users\22041912\Documents\User_statis_list.csv
    In Powershell my script working normally and writing CSV file but in scheduled task cant write CSV file. Task history told me succesfully finished.
    Anyone suggest? What wrong?

    copy this on a batch file and point the task scheduler to the batch file.
    PowerShell.exe -WindowStyle Hidden  -File
    E:\Shell\OdmaaGet-Aduser.ps1 
    check if it works..
    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.
    IT Stuff Quick Bytes

  • Powershell script generating duplicate results

    Hi All,
    Having a bit of an issue with a script, the objective of the script is to check a CSV file of user aliases and compare it with Exchange MailUser accounts. If the account exists then output a sting and if it does not exist output a string. It seems that the
    ForEach loop is running multiple times against each user.
    Any ideas?
    if (!(Get-PSSnapin | Where-Object { $_.name -eq "Microsoft.Exchange.Management.PowerShell.Admin" }))
    ADD-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
    $filename = (Get-Date).ToString("dd-MM-yyyy")
    $a = "<style>"
    $a += "BODY{background-color:#E6E6E6;}"
    $a += "TABLE{border-width: 2px;border-style: solid;border-color:
    black;border-collapse: collapse;}"
    $a += "TH{border-width: 2px;padding: 12px;border-style: solid;border-color:
    black;background-color:#A4A4A4;text-align:center}"
    $a += "TD{border-width: 2px;padding: 6px;border-style: solid;border-color:
    black;background-color:#58ACFA;text-align:center}"
    $a += "</style>"
    Function Get-UserStatus {
    Import-CSV c:\MailUsers.csv | % {
    $user = $_.Alias
    ForEach ($item in $User) {
    $mailuser = Get-Mailuser $item
    If ($mailuser -eq $Null) {$NotFound = "$item ---- does not exist, please remove Domino Migration Status!"}
    Else {$Found = "$item ---- has been found"}
    New-Object PSObject -Property @{
    'NotFound' = $NotFound;
    'Found' = $Found;
    Get-UserStatus | Select NotFound, Found | ConvertTo-HTML -head $a -body "<H1>MailUser Check - $filename</H1>" | Out-File c:\user.html

    Function Get-UserStatus {
    Import-CSV c:\MailUsers.csv | % {
    $user = $_.Alias
    ForEach ($item in $User) {
    $mailuser = Get-Mailuser $item
    If ($mailuser -eq $Null) {$NotFound = "$item ---- does not exist, please remove Domino Migration Status!"}
    Else {$Found = "$item ---- has been found"}
    New-Object PSObject -Property @{
    'NotFound' = $NotFound;
    'Found' = $Found;
    }I see two "foreach" together.. maybe using this?:Function Get-UserStatus {
    Import-CSV c:\MailUsers.csv | % {
    $item = $_.Alias
    $mailuser = Get-Mailuser $item
    If ($mailuser -eq $Null) {$NotFound = "$item ---- does not exist, please remove Domino Migration Status!"}
    Else {$Found = "$item ---- has been found"}
    New-Object PSObject -Property @{
    'NotFound' = $NotFound;
    'Found' = $Found;
    I havent checked the script carefully, but the corrected one above may work..

  • How to make the result showing one time and make the result to csv file?

    My script having problem of showing out all the AD computer name result  from Active Directory once when running it and storing the result to csv file. I am a newbie in AD and powershell.
    This is the code:
    $strADPathFile = "D:\Powershell for AD\ADPathList.txt"
    $strErrLogFile = "D:\powershell for AD\errorADComputer.log"
    $arrADPath = Get-Content -Path $strADPathFile
    foreach ($strADPath in $arrADPath)
    try
    $objSearch = New-Object DirectoryServices.DirectorySearcher
    $objSearch.Filter = '(objectCategory=computer)'
    $objSearch.SearchRoot = $strADPath
    $objSearch.SearchScope = "Subtree"
    $objSearch.PageSize = 1000
    $objResults = $objSearch.Findall()
    write-host "Retrieving AD computer information in the domain $strDomain"
    write-host "Number of AD Computer Name result: "$objResults.Count
    foreach($objResult in $objResults){
    $objComputer = $objResult.GetDirectoryEntry()
    write-host $objComputer.dNSHostName
    try
    # InsertSQLTable $objComputer
    catch
    write-host $error[0]
    $strError = $objComputer.dNSHostName + " " + $dateNow + $error[0]
    Add-Content $strErrLogFile $strError
    catch
    write-host $error[0]
    Export-Csv D:\PowerShellforAD\test2.csv
    This is the error that I had get is that it will get the result for 2nd time again.
    By the way, what is InputObject about? I had research some of it and still did not quite get it. Can anyone explain? Thanks 

    Hi,
    in the final line you call Export-Csv. which is a great command at exporting information. However, for it to work it needs a path to export to (D:\PowerShellforAD\test2.csv in your case) and Information (InputObject) to export.
    You do not give that command any Information, so it throws an error.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • HT2486 how can I export the contact book data to a csv file for editing?

    how can I export the contact book data to a csv file for editing?

    You can edit a card right in Contacts. No need to export and re-import.
    Select a name and on the right side, click the Edit button:

  • How do i convert a pdf into an xls or csv file

    how do i convert a pdf into an xls or csv file   ? thnx

    HI newapiary
    You can either use Adobe Acrobat or Adobe ExportPDF Online Service.
    Please Refer : https://www.acrobat.com/exportpdf/en_GB/convert-pdf-to-word.html

  • How to get Mountain Lion Spotlight to find text in CSV files?

    Does anyone know how to get Mountain Lion Spotlight to find text in CSV Files? Spotlight worked flawlessly with Snow Leopard on my last MAC but with Mountain Lion it doesn't recognize CSV Files. I have researched this extensively and haven't found any solution but I really believe there must be many others who have the same problem. I even contacted Apple's Genius Bar which was of no help whatsoever, they couldn't even tell me why Spotlight wasn't finding text in CSV Files, i.e., function dropped by Apple, bug, etc.
    Thru research I found that if the CSV Files are converted to 'Plain Text Files' Spotlight will find text inside of the files but I typically save my spreadsheets as CSV Files and don't want to have to convert them to Plain Text Files just so Spotlight will search them.
    I appreciate any help you can give.
    Joel

    I should have mentioned earlier that I do NOT have any exclusions set under the Spotlight Privacy tab, however, I did move one of the folders that contains CSV Files in then back out of the Privacy tab to try and get Spotlight to index the folder, but to no avail.
    I have a second Admin account and tried to find text in CSV Files while in that account, again to no avail. I also tried upgrading to Mountain Lion 10.8.4 to see if it might fix the problem, but no soap.
    Below is a screenshot of the Systems Preferences/Library/Spotlight/RichText.mdimporter/ file and I don't even see where Spotlight is setup to find CSV Files on my computer, very confusing but thanks again for your input.

  • Import-csv how to make powershell ignore a line in a csv file if a column contains a certain value

    Basically I got a very basic script that uses a csv file to input values needed to remove people from a distro list. That part is working fine. I'd like to add to it's functionality so it can look at values in a certain column, and if any of those certain
    values are present, I want powershell to skip that line and not process it. For instance I have a column in the csv called Group. If I have a listing under Group that says ABC I want the script to skip that line and not try to process it. What could I insert
    into the script to acheive this?

    You're welcome. You can add to the if test with -and:
    Import-Csv .\groups.csv | ForEach {
    If ($_.Group -ne 'ABC' -and $_.Group -ne 'DEF') {
    Write-Output "Group is $($_.Group)"
    Write-Output "Name is $($_.Name)"
    Output:
    Group is GHI
    Name is Show Me
    groups.csv:
    Group,Name
    ABC,Skip Me
    DEF,Skip Me Too
    GHI, Show Me
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Creating Powershell script to run against Multiple XML Files: Correcting Nordic characters. Renaming only the files that were corrected.

    Greetings,
    I am new to powershell and scripting and would like to create a powershell script to do the following to XML files.
    I would like to change the data received in XML files that contains special Nordic characters: such as 
    ä, Ä, é, ö, Ö, ü, Ü, and ß respectfully.
    The file names that gets drop to me come in with the following naming convention: C54ABC_111120140500_1, C54ABC_111120140500_2, C54ABC_111120140500_3, C54ABC_111120140500_4 all the way to C54ABC_111120140500_12.
    By automating the script, I would like the script to look into a directory containing these files and access the data within it and change the the data that has the special characters to the English Dictionary character equivalent.
    e.g. ä for a, Ä for A, é for e, ö for o, Ö for O, ü for u, Ü for U, and ß for ss.
    Once that step is complete. I would like to rename the file from C54ABC_111120140500_1.xml to C54ABC_111120140500_1_rctf.xml (adding an additional 5 characters to the end of a file that was corrected) if the file did not need any correction then renaming is
    not needed.
    the working directory (Source and destination) will remain in the same location. e.g. C:\Temp\
    Currently I was able to come up with the following, however I am stuck when it comes to the renaming part since, it requires "IF and Else" statments .... I think.
    $Source = "C:\Temp"
    $Destination = "C:\Temp"
    $regex33 = "\*.xml"
    (Get-Content $regex33) |
    ForEach-Object {$_ -replace "ä", "a" -replace "Ä", "A" -replace "é", "e" -replace "ö", "o" -replace "Ö", "O" -replace "ü", "u" -replace "Ü", "U" -replace "ß", "ss"}
    #Rename-Item -NewName {$_.name -replace -whatif}
    Your Assistance and Expertise is greatly appreciated.
    Thank you in advance KC.

    Hi KC
    You could try something like this.
    Let me know how you get on and if you've any questionds.
    cheers, Tim
    $Source = 'C:\Temp'
    Set-Location $source
    $xmlFiles = Get-ChildItem -Path $source -Filter *.xml
    ForEach ($xmlFile in $xmlFiles)
      $content = Get-Content -Path $xmlFile.FullName
      $renameFile = $false
      Switch -Wildcard ($content) {
        '*ä*'
          $renameFile = $true
          $content = $content -creplace 'ä', 'a'
        '*Ä*'
          $renameFile = $true
          $content = $content -creplace 'Ä', 'A'
        '*é*'
          $renameFile = $true
          $content = $content -creplace 'é', 'e'
        '*ö*'
          $renameFile = $true
          $content = $content -creplace 'ö', 'o'
        '*Ö*'
          $renameFile = $true
          $content = $content -creplace 'Ö', 'O'
        '*ü*'
          $renameFile = $true
          $content = $content -creplace 'ü', 'u'
        '*Ü*'
          $renameFile = $true
          $content = $content -creplace 'Ü', 'U'
        '*ß*'
          $renameFile = $true
          $content = $content -creplace 'ß', 'ss'
      If ($renameFile)
        $newFileName = "$($xmlFile.BaseName)_rctf.xml"
        $content | Out-File -FilePath $xmlFile.FullName -Force
        Rename-Item -Path $xmlFile.PSChildName -NewName $newFileName

  • How do I stop Apple Script from leaving a Text.txt file with each image downloaded using Photo Downloader in Adobe Photoshop CS4_Bridge???

    I use Adobe Photoshop CS4_Bridge _Photo Downloader to import images from CF Cards into my 11" Mac Book Air.  I have an issue with the Text files
    that seem to accompany each and every image that I do not need.  How do I stop Apple Script (which I assume is the culprit in this case)  from interferring with this process.

    Your iWeb Site is stored not on your iDisk, but on a file named Domain.sites in your ~/Home/Library/Application Support/iWeb/ Folder.
    If , for whatever reason, you wipe your HD and/or lose this file (Get a new computer, Re-Install your OS, Stolen Laptop, Crashed HD, Etc.) without backing-up your Domain.sites file then you will have to re-build your iWeb sites from scratch again.
    Of course you can edit your Published HTML files in a different program such as Dreamweaver or even Text Edit. You just can't edit Published HTML files in iWeb. Not at this time at least.
    Use iWebBackup to backup your Domain file to a Blank CD or DVD. Backing up your Domain file to another folder on your computer is not fully backing it up. If your computer gets stolen you still lost the file but if you have your Domain file burned onto a CD you have a backup!
    Download iWebBackup Here
    You can use iWebExtender to automatically consolidate your files into one folder and delete multiple images.
    http://iWebFAQ.com

  • PowerShell Script for updating accounts in CSV

    Hi Experts...!!!!
    I need to have a power shell script that can update the status(Enable/disable) accounts given in a .csv file with DNs of the user accounts in it....
    Any suggestions...
    Thank You... 
    TechSpec90

    I recommend that you start by searching for answers:
    This comes up as the first item in a search:
    https://technet.microsoft.com/en-us/library/ee617200.aspx
    \_(ツ)_/

  • Using PowerShell to Add Columns to A CSV File

    Hello,I wonder if someone can shed some light on this. I have a PowerShell script which has been working perfectly well pulling tab-seperated text log files off individual PCs, adjusting the data within and combining them into a single CSV for processing by our reporting tools via Excel and SQL. These files are call history logs generated by Toshiba Call Manager software installed on each PC. They keep a log of every call made by the phone linked to the individual user's software. By combining them for reporting, we get a clear and accurate picture of time spent on the phone etc.The problem we have is I need two extra columns added. One is for the person's name ('Person'), taken from the log file name, the other is a column for the call duration (which is logged under 'Dur' as a unit of time, e.g. 4:12 for 4 mins 12 seconds) and we...
    This topic first appeared in the Spiceworks Community

    Hello,I wonder if someone can shed some light on this. I have a PowerShell script which has been working perfectly well pulling tab-seperated text log files off individual PCs, adjusting the data within and combining them into a single CSV for processing by our reporting tools via Excel and SQL. These files are call history logs generated by Toshiba Call Manager software installed on each PC. They keep a log of every call made by the phone linked to the individual user's software. By combining them for reporting, we get a clear and accurate picture of time spent on the phone etc.The problem we have is I need two extra columns added. One is for the person's name ('Person'), taken from the log file name, the other is a column for the call duration (which is logged under 'Dur' as a unit of time, e.g. 4:12 for 4 mins 12 seconds) and we...
    This topic first appeared in the Spiceworks Community

Maybe you are looking for

  • Can't access my iTunes on my external hard drive

    I have been putting my music (both downloaded from iTunes and burned from my CDs) onto an external hard drive and until this week, it's worked out well. Recently, I had a friend take off Windows Vista (it came with my laptop) and install Windows XP.

  • PSE 11 Slide Show show date

    Is it possible to display the 'shot date' of photos witin a Slideshow.  In showing a slideshow, I'm being asked; "when was that pix taken?".  It would help answering these questions by having the shot date shown.  thanx

  • Run OC4J 903 on linux in the background?

    I am relatively new to Linux and have been trying to start OC4J either automatically or as a background process (so that I do not have to keep the terminal window open). I tried "$nohup java -jar oc4j.jar &", but OC4J still shuts down when I logout o

  • How I protect edition in some pages of my PDF, but accept modify one page in my PDF file?

    How I protect edition in some pages of my PDF, but accept modify one page in my PDF file? For example... I am author of a e-book. But, I want people distribute that my e-book inserting in first page your website of who is distributing. Look at how I

  • Adobe form as input to approval workflow

    I have not used Adobe form before, so please bare with me! I have a couple of basic questions. Do I have to download the Adobe designer software from sap marketplace, or is it on the SAPGUI install cd? Do I need the Adobe designer s/w or is there a s