Powershell: loop from text file line by line + more

  • Grab every file in specified folder/directory
  • Read each file line by line
  • Create / append new file from output
  • After file has been created join / merge to file
  • Merge header & footer Files plus new file into one  large file
#Folder of something
#grab the flies
Get-ChildItem C:\Users\Desktop\powershell\vmat\itnetlabsVAMT\ -Recurse |
 Where {$_ -IS [IO.FileInfo]} |
#GET CONTENT $_ means each line from get content
gc $_ | ForEach-Object {

 #Shows what you grabbed
write-host ($_)

######################
#write the output to a file
write-output ' <Computer Name="'($(_))'"
 OSVersion="" OSEdition="" NetworkType="Domain" NetworkName="
" Id="bac224">
 <MacAddresses />
<Products>
<Product>
<Sku Id="00000x00-0000-0000-0000-0x00" Name=""
ApplicationId="5c3f16059f" Description="" />
<LicenseInfo LicenseStatus="Unknown" LicenseStatusReason="0"
 GracePeriodRemaining="0" GenuineStatus="Unknown"
TokenEnabled="false" LicenseIsAddon="false" />
<Version />
<PartialProductKey />
<ProductKeyId />
<KeyType>Unknown</KeyType>
<InstallationId />
<ConfirmationId />
<LastErrorCode>0</LastErrorCode>
<LastActionState />
<LastUpdateTime>2012-03-08T10:39:24.0468d-06:00</LastUpdateTime>
<LicenseFamily />
</Product>
</Products>
</Computer>
</Computers>'
} | Out-File $($pathName + "_DUMP.txt")
#ABOVE LINE PIPe OUTPUT TO TEXT FILE
#MAKES A TEXT FILE
New-Item -ItemType file "big.cli"
#merges the files
$file1 = Get-Content "header.txt"
$file2 = Get-Content $($pathName + "_DUMP.txt")
$file3 = Get-Content "Footer.txt"
Add-Content "big.cli" $file1
Add-Content "big.cli" $file2
Add-Content "big.cli" $file3

<code></pre></code>
<code>

[\powershell]

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki
1 Comment

Learning powershell: scripting User Accounts in Active Directory

Powershell scripting users
I would recommend building out a testing domain controller using oracle virtual box.(SAND BOX TESTING!)
Lets get start making some users to test with powershell.

A. Use this CSV from StarTrek user list CSV FIIL  (http://www.powershell.nu/2009/04/13/part-11-adding-ou-structure-using-powershell/ ::: a awesome site )

You can also create more users by grabbing them from  http://fake.name-generator.co/index.php

 

 

 

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki
0 Comments