Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AzureADPreview dependency Windows 365 Cloud PC Usage Report #14

Open
MietekW opened this issue Jun 29, 2022 · 0 comments
Open

Remove AzureADPreview dependency Windows 365 Cloud PC Usage Report #14

MietekW opened this issue Jun 29, 2022 · 0 comments

Comments

@MietekW
Copy link

MietekW commented Jun 29, 2022

First thanks for time and effort spent for providing these scripts.
I am to time constraint to do a PR for this so I hope it is ok, to share it via this post.

I am not able to share my script as I use DevOPS so removed 85% of the code for the [Windows 365 Cloud PC Usage Report] script.

Some things that I encountered or changed.
The current version check for the mggraph version does not work, as it does a compare on a string value for version(not on a integer), so this has no added benefit.
I would suggest to remove this or rewrite it so it does upgrade or ask for a upgrade, no added benefit with the current check as the scripts continues to work.

The second is I do not like to be using the AzureADpreview module, so I replaced the line:
$Logons = Get-AzureADAuditSignInLogs -Filter "startswith(userPrincipalName,'$($CloudPCUser.UserPrincipalName)') and appdisplayname eq 'Windows Sign In' and createdDateTime gt $string"

With:
$Logons = Get-MgAuditLogSignIn -Filter "startsWith(userPrincipalName,'$($CloudPCUser.UserPrincipalName)') and appdisplayname eq 'Windows Sign In' and createdDateTime gt $string"

And removed all lines of code that were needed for the AzureADpreview connection.
This way it 100% uses the mggraph modules.

The code below does not work as the variable $total is never set $count should be used.

Line 255
if ($total -eq 0) { write-host "User has not logged in." -ForegroundColor Red }

I rewrote that to this so it also writes an entry that no logons were found in the past $offset days.

    #Counts each web logon
    foreach ($Logon in $Logons) {

        if (($Logon.UserPrincipalName -eq $CloudPCUser.UserPrincipalName) -and ($Logon.DeviceDetail.Displayname -like "CPC-*") -and ($Logon.DeviceDetail.DeviceID -eq $CloudPCUser.AadDeviceId)) {
            $count = $count + 1

            if ($logon.CreatedDateTime -gt $LastLogon) { $LastLogon = $Logon.CreatedDateTime }    
             #outputs local client logon count
    write-host "Logon count is $count"
    $output.Logons = $count

    #outputs the last logon time
    write-host "User's last logon time is(UTC)"$LastLogon
    $output.LastLogon = $LastLogon
        }
    }
    #outputs notification if no logon activity has been recorded
    if ($count -eq $null) {
        
        $count = 0
        write-host "No logons found in past $offset days."
        $output.Logons = $count
        $output.LastLogon = "No logons found in past $offset days."
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant