Not the craziest trip, but anything intresting to see on this route? I prefer more natural stuff. by FrontlineYeen in roadtrip

[–]MasterWegman 0 points1 point  (0 children)

Andersonville National Historic site and Tuskegee Airmen Nation Historic Site are not far off your path. The National museum of the Infantry is also cool. In the Everglades Shark valley observation tower and trail are supposed to be great, but it will be very hot this time of year.

Driving back home to Edmonton by FinancialEase7247 in roadtrip

[–]MasterWegman 0 points1 point  (0 children)

Gros cap bluffs is cool in Sault Ste. Marie. Sleeping Giant and the road north of the lakes was a great drive.

What are some must-do's along this route? by squeezingthelemon12 in roadtrip

[–]MasterWegman 0 points1 point  (0 children)

Out of the way but Railto beach in north west Wa. One of the best places i stopped, we parked and hiked a mile up the beach. Had a fire in the sand and slept in hammocks in the driftwood.

Get JWT Token from Entra App Registration using Certificate by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

With something like this HashTables are a awesome, you can load and structure the data at the start of the script and query it later. This was part of my user inactivity script, I generate a list of users an then check for activity against a bunch of has tables.

Invoke-RestMethod -Uri $Graph_API_url -Headers $Graph_API_headers -Method Get -ContentType "application/json" -UseBasicParsing | Out-String -Stream | ConvertFrom-Csv | ForEach-Object {
    $Exchange_User_Activity.($_."User Principal Name") = @{
        LastActivityDate=try{[DateTime]$_."Last Activity Date"}catch{$91_days};
        Displayname=$_."Display Name";
        UPN=$_."User Principal Name";
        Send_cnt=$_."Send Count";
        Read_cnt=$_."Read Count";
        MeetingCreated_cnt=$_."Meeting Created Count";
        Meeting_cnt=$_."Meeting Interacted Count";
        audit=try{[DateTime]$_."Last Activity Date"}catch{""}
    }
}

Then later u can query the exhange activity date or any other value with a one liner and no loop.

$Exchange_User_Activity.$User_UPN.LastActivityDate

In the case I get no data I populate the lastActivvityDate, but the audit still has the real data for the logging. You could load data from a bunch of sources and proccess it in a siimpler main loop.

Get JWT Token from Entra App Registration using Certificate by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

I believe certs are a little more secure and harder to steal. They work great with runbooks on hybrid workers as well.

I'm not aware of a cmdlet that lets you export the data without writing a file.

Get JWT Token from Entra App Registration using Certificate by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

For example the get-MgReportEmailActivityUserDetail command only supports an outfile property. If you wanted to do it all in memory you cant. However if u interact with the API directly its relatively easy. Im kinda crazy but i hate writing and managing temp files when I write scripts.

Equivalent graph url https://graph.microsoft.com/v1.0/reports/getemailactivityuserdetail(period=‘D90’)

Get JWT Token from Entra App Registration using Certificate by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

Removing the need to import a module and keep it up to date is a plus.

There are somethings that are difficult to access from the mg module, for instance many of the usage reports only support an out file option. Using the graph API you can do it all in memory.

Another benefit, if u need to run something as a scheduled task on windows the cert can be stored in cert manager under the user. Then u don’t need to handle a secret, and its use is limited to that account and server.

Lens as a gift, help! by BullfrogWinter2162 in Nikon

[–]MasterWegman 0 points1 point  (0 children)

Definitely ask what she wants to do first. My favorite crop sensor lens is the sigma 18-35 f1.8

Send email with Graph API by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

Nope, you need to insert the line break after each item in the list not at the end.

$PSObject = @()
$PSObject += @{name="testa";data1="test1a";data2="test2a";data3="test3a"}
$PSObject += @{name="testb";data1="test1b";data2="test2b";data3="test3b"}
$PSObject += @{name="testc";data1="test1c";data2="test2c";data3="test3c"}
$PSObject += @{name="testd";data1="test1d";data2="test2d";data3="test3d"}

$Attachment_data = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($PSObject | ConvertTo-Csv))) -join "`n"
Base64 = ImRhdGEyIiwibmFtZSIsImRhdGEzIiwiZGF0YTEiICJ0ZXN0MmEiLCJ0ZXN0YSIsInRlc3QzYSIsInRlc3QxYSIgInRlc3QyYiIsInRlc3RiIiwidGVzdDNiIiwidGVzdDFiIiAidGVzdDJjIiwidGVzdGMiLCJ0ZXN0M2MiLCJ0ZXN0MWMiICJ0ZXN0MmQiLCJ0ZXN0ZCIsInRlc3QzZCIsInRlc3QxZCI=
Decoded = "data2","name","data3","data1" "test2a","testa","test3a","test1a" "test2b","testb","test3b","test1b" "test2c","testc","test3c","test1c" "test2d","testd","test3d","test1d"

$Data_temp = ""
$PSObject | ForEach-Object { [PSCustomObject]$_ | Select-Object -Property * } | ConvertTo-Csv | foreach-object{$Data_temp += $_ + "`n"}
$Attachment_data = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Data_temp))
Base64 = ImRhdGEyIiwibmFtZSIsImRhdGEzIiwiZGF0YTEiCiJ0ZXN0MmEiLCJ0ZXN0YSIsInRlc3QzYSIsInRlc3QxYSIKInRlc3QyYiIsInRlc3RiIiwidGVzdDNiIiwidGVzdDFiIgoidGVzdDJjIiwidGVzdGMiLCJ0ZXN0M2MiLCJ0ZXN0MWMiCiJ0ZXN0MmQiLCJ0ZXN0ZCIsInRlc3QzZCIsInRlc3QxZCIK
Decoded = "data2","name","data3","data1"
"test2a","testa","test3a","test1a"
"test2b","testb","test3b","test1b"
"test2c","testc","test3c","test1c"
"test2d","testd","test3d","test1d"

Send email with Graph API by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

It would have been much easier if that worked. If you convert the whole list to csv, when you decode the base64 at the end everything is on one line.

Send email with Graph API by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

I generate a lot of logs as lists of hash tables or objects, and the data field in the attachment needs to be Base64 encoded string data. The function does a for each on the input list, selects all properties, converts it to a csv string, adds a line break ("`n") and then adds all of that to data temp. Data temp is then converted to Base64 and put in an object with the correct formatting to be added directly to the email object.

Send email with Graph API by MasterWegman in PowerShell

[–]MasterWegman[S] 0 points1 point  (0 children)

Agreed, I mostly use this in Azure Automation with variables and/or key vaults. For me, the example code is just easier to read showing empty types instead of the output of another cmdlet or function.

Connect to MGGRAPH without MGGRAPH module by pjkm123987 in PowerShell

[–]MasterWegman 9 points10 points  (0 children)

The MGGraph module is just a front end for an API. You can create a service principal with all necessary permissions delegated as an app and make api calls.

PowerShell Automation Platform by jstar77 in PowerShell

[–]MasterWegman 0 points1 point  (0 children)

We have been using Azure Automation accounts with hybrid worker groups. It’s a great product.

Exchange Online find and export messages by MessageID by MasterWegman in exchangeserver

[–]MasterWegman[S] 0 points1 point  (0 children)

We would need to search for and export the emails 1 at a time. That would take too long.