Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MSAdministrator/e7550bcc4236c3857a78ffbca579f9bc to your computer and use it in GitHub Desktop.
Save MSAdministrator/e7550bcc4236c3857a78ffbca579f9bc to your computer and use it in GitHub Desktop.
Convert-SabaToCampus2ndIssue
<#
.Synopsis
This function will convert a Saba CSV for University Campus
.DESCRIPTION
This function will import a CSV, modify the values, and export it to a new CSV.
We rename the following headers:
Person EMPID to EMPID
Completed Courses (Transcript) Ended/Completed On Date to Completed On Date
Course Course ID to Course ID
.EXAMPLE
C:\> Convert-SabaToCampus2ndIssue -InFile C:\users\user\desktop\infile.csv -OutFile C:\users\user\desktop\outfile.csv
#>
function Convert-SabaToCampus2ndIssue
{
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
SupportsShouldProcess=$true,
PositionalBinding=$false,
HelpUri = 'http://www.microsoft.com/',
ConfirmImpact='Medium')]
[Alias()]
[OutputType()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[Alias("CSV")]
$InFile,
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
$OutFile
)
Begin
{
$ReturnObject = @()
$DataIn = Get-Content -Path $InFile | Select-Object -Skip 5 | ConvertFrom-Csv
}
Process
{
foreach ($d in $DataIn)
{
if ($pscmdlet.ShouldProcess("Target", "Operation"))
{
$CompletedDate = [DateTime]::Parse($d.'Completed Courses (Transcript) Date Marked Complete')
$date = (Get-Date $CompletedDate).AddYears(2)
$props = [ordered]@{
EMPCOMP = 'EMPCOMP'
EMPID = $d.'Person EMPLID'
'Course Title' = ($d.'Course Title').substring(0,3).ToUpper()
'Completition Status' = $d.'Completition Status'
'Completed On Date' = Get-Date $date -Format 'MM/dd/yyyy'
}
$tempObj = New-Object -TypeName PSCustomObject -Property $props
$tempObj | ConvertTo-Csv -Delimiter '|' -NoTypeInformation | % {$_.Replace('"','')}
$ReturnObject += $tempObj
}
}
}
End
{
$returnobject | Export-Csv -Path $OutFile -Force -NoTypeInformation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment