PowerShell import-CSV create new file type HTML using group membership

PowerShell Task:

  • Import CSV
  • Read import-csv line by line
  • Match Non AD group To a users folder
  • Create an HTML page from powershell
  • Create a hyper link in each folder from  PowerShell
  • base membership from a non AD source.

The task was to use a CSV file from an outside source that would create an HTML page with its HTML link based on the content of import-csv file.
The group member ships in the CSV file did not come from  AD but based on a directory structure

#########################
#########################
# //===Name: .\easy_ImportCsv.ps1
# Description:www.BrilliantlyEasy.com import
# from CSV export to HTML File by
#          a NoN AD group memberships
# ########    Create HTML URL Links
#By Group in user folders
#
#####################################</pre>
write-host $objItem.Name, $objItem.WorkingSetSize `

 -foregroundcolor "magenta"
#var for date/time
$datetime = get-date -format G

#Var $OFS used for new lines when using write-host
$OFS = "`r`n`r`n"
$OFS1 = "`n"

#Source of users

#var used for team memberships in import-csv
$Red = "Marketing"
$Green = "Sales"
$Blue= "Development"

write-host $OFS  $datetime $OFS1 `
"IMPORT FILE NAME: C:\scripts\powershell\portfoiloportStu.csv" `
-foregroundcolor "magenta" -backgroundcolor "yellow"
#import-csv "c:\import\accountsInfo.csv"

#Var for source of folder location

$source = "C:\users\folder"

#Var for CSV import of user files
$csv_info = Import-Csv C:\scripts\powershell\portStu.csv

foreach ($line in $csv_info)
{
#$destination = "C:\users\folder\" + $line.Username

#powershell create HTML file and HTML code content
# from a Variable with variables inside of HTML
#*look at the new-item -force -value $outFile
$outFile ='
<img alt="image" longdesc="image" width="846" height="62" />
<table style="width: 57%;">'$outFile =  $outFile +
 '$outFile =  $outFile + $line.Username
$outFile =  $outFile +  '
#Var that holds the full path to user GROUP & their User name
# powershell destination use path in a variable with quotes
#by use of + syntax
$destination = "C:\users\folder\"+$line.Group_Role+"\"+ '
$line.Username
#write-host "1" $($line.Username) $($line.Link) `
$($line.Group_Role)
#if red grab the user in Red Groupif  ($Red -eq $line.Group_Role)
{write-host "RED GROUP" $OFS1  $line.Username $line.Link
`$line.Group_Role#Powershell Create a new HTML  survey.html file
# using Variable  to spit out HTML
#code content based on CSV importnew-item -path $destination -name
survey.html -type file `-force -value $outFile}
#elseif red grab the user in
# Green Groupelseif ($Green -eq  $line.Group_Role)
{Write-Host "Green Group"     $OFS1  $line.Username $line.Link
`$line.Group_Rolenew-item -path $destination -name survey.html -type file
`-force -value $outFile}
#elseif red grab the user in Blue Groupelseif
 ($Blue -eq $line.Group_Role){Write-Host "Blue Group"
$OFS1  $line.Username $line.Link
`$line.Group_Role#Powershell Create a new HTML file  survey.html
#using Variable  to spit out HTML code content new-item -path
$destination -name survey.html -type
`file -force -value $outFile}else {"Users have been imported. "}}
#END

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki
No comments yet.

Leave a Reply