Please help me understand this

hello, I am trying to understand this code and I’ve tried to put comments line by line, not sure if correct and not sure what the other lines do… hope someone can help explain? Thanks

$end = get-date // get-date result assign to end variable

$alldesks = get-content nsw.txt //get txt inside nsw.txt and assign to alldesks variable

foreach ($desk in $allDesks) { //loop, search for “desk” text in variable alldesks)

$object = Get-CalendarDiagnosticObjects -Identity $desk -StartDate “1/07/2020” -EndDate $end -ResultSize unlimited | where-object {$.ResponseType -eq 3 -and $.itemversion -eq 2 }| select EndTime,Location,SentRepresentingEmailAddress
// not sure what this does,

$date = Get-Date -Format yyyyMMdd //get-date and put in variable date using format yyyymmdd
$file = $date+“-NSW.csv” //concatenate date to NSW.CSV
foreach ($obj in $object) { //loop not sure where obj came from?

$users = Get-User $obj.SentRepresentingEmailAddress | select name //get-user obj.property assign to users variable?
$split = ($obj.Location).split(“-”).trim() //not sure what this does

$output = New-Object psobject //assign value to output variable
$output | Add-Member noteproperty “Endtime” $obj.endtime //not sure what this does
$output | Add-Member noteproperty “Building” $split[0] //not sure what this does
$output | Add-Member noteproperty “Floor” $split[1] //not sure what this does
$output | Add-Member noteproperty “Desk” $split[2] //not sure what this does
$output | Add-Member noteproperty “User” $users.name //not sure what this does

$output | export-csv -notypeinformation $file -append
}

}

$end

jd,
Welcome to the forum. :wave:t3:

Have you tried to search for it? For most PowerShell cmdlets the documentation is quite comprehensible - with an explanation for each individual parameter and some examples.

You may start with learning how to read the help:

… and you’d continue with the help for the individual cmdlets you want to learn about …

… and so on and on …

The creation of the variable $output is a little dated - where did you get this code from? :wink: Today we’d use a

And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

(Sometimes the preformatted text button hides behind the settings gear symbol :wink: )

1 Like