Posts

Showing posts with the label Powershell

CMD Print DIR to text file

dir > print.txt The ">" symbol is telling to put the output of the command to whatever is next. In this case "print.txt". This is useful for writing any output to a file in a script or whatever. Example: dir > %USERPROFILE%\Desktop\print.txt This example will print the directory listing to print.txt on your desktop. Other flags: dir /b file names only dir /s include all sub folders & files Original source:  http://www.computerhope.com/issues/ch000772.htm Actually I really like that site, and spent some time taking their quiz. Entertaining.

CMD combine CSV files into one

Image
I had the need to combine several CSV (excel) files into one file. The set was long enough that even opening them and copy/pasting would take over an hour. This little trick will do it in a few seconds. (in windows) 1. Put all of your files in the same folder. They all need to be CSV format and should be the only CSV files in the folder. You may want to remove headers from your spreadsheets if you don't want them later. 2. Open a command prompt. Windows+R > cmd This should be the normal command prompt because it doesn't work in powershell. 3. Navigate to the folder with your .csv files 4. type " copy *.csv newfilename.csv " 5. A new file named "newfilename.csv" will show up in the same folder. If you wanted to copy it somewhere else you could run copy *.csv path\newfilename.csv. Example: copy *.csv  %USERPROFILE%\Desktop\newfile.csv This will copy all the CSV files from the folder you are in to a file on your desktop named newfile.csv...

Export Domain Users to CSV with PowerShell

Image
If you would like to create a list of all domain users in excel with a powershell script you are in luck. Quest software has created some pretty awesome tools to manage Microsoft Active Directory. Here's how to do it: 1.   You'll need to install the Quest ActiveRoles management shell v. 1.4 or later, located here:  http://www.quest.com/powershell/activeroles-server.aspx 2. Create a PowerShell file with the following script. Basically, just copy this text into a text file and rename the extension to .ps1. #This script requires Quest ActiveRoles management shell v.1.4 or later and Powershell to be installed. http://www.quest.com/powershell/activeroles-server.aspx #The script may be run on any machine that is bound to the domain and actively connected. You do not have to be a domain administrator. #Two files will be created. One CSV with results and one TXT log file. $strTimestamp =  [string](Get-Date -format "yyyy-MM-dd_hh-mm") start-transcript DomainScript...

Export Domain Admins to CSV with Powershell

It would be nice to be able to run a PowerShell script to query certain domain groups in Microsoft Active Directory, and write them to .CSV files for easy review in excel. Here's one way to do it: 1. You'll need to install the Quest ActiveRoles management shell v. 1.4 or later, located here:  http://www.quest.com/powershell/activeroles-server.aspx 2. Create a text file with .ps1 extension, and the following text. You can review the comments in the script to see what each part does, or just google the commands you don't know. Quest has some documentation last time I checked. #the AD groups that will be queried. These are groups that are considered domain admins $aGroups = @("Administrators", "Domain Admins", "Server Operators", "Enterprise Admins", "Account Operators", "Backup Operators", "Group Policy Creator Owners", "Schema Admins",  "Domain Controllers") #where the resu...