mobileMobil Cihaz Temizleme Scripti

These scripts must be executed in an Exchange Server environment.

circle-info

Remove-MobileDevice -Identity $mobile.Id -Confirm:$false

Commenting out this line by adding a # prefix and utilizing the associated Set command allows you to generate a report before final execution. This approach is recommended for small-scale environments; however, in larger infrastructures, the reporting process can be time-consuming. Please note that re-running the command for actual execution after the reporting phase will require an additional wait for the same duration.

Adding the -WhatIf parameter to the command enables you to simulate the operation and view the results without applying any permanent changes.

. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell
 
$mobiles=Get-MobileDevice
$rap=@()
 
Foreach ($mobile in $mobiles) {
    $easstate=Get-MobileDeviceStatistics -Identity $mobile.Id
    $userdn=($mobile.DistinguishedName.Split(","))[2..1000] -join (",")
    $user=Get-Mailbox -Identity $userdn
    Write-Host $mobile.Id " isleniyor" -ForegroundColor Yellow
    $ent="" | select DisplayName,Email,DeviceUserAgent,LastSuccessSync,FirstSyncTime,DeviceAccessState,Silindi
    $ent.DisplayName=$user.DisplayName
    $ent.Email=$user.PrimarySmtpAddress
    $ent.DeviceUserAgent=$mobile.DeviceUserAgent
    $ent.LastSuccessSync=$easstate.LastSuccessSync
    $ent.FirstSyncTime=$easstate.FirstSyncTime
    $ent.DeviceAccessState=$mobile.DeviceAccessState
$deviceid=$mobile.deviceID
 
If($easstate.LastSuccessSync -lt (get-date).AddMonths(-3)) {
    Write-Host $user.DisplayName `t $mobile.DeviceUserAgent `t $easstate.LastSuccessSync " siliniyor" -ForegroundColor Green  
    Remove-MobileDevice -Identity $mobile.Id -Confirm:$false    
    
    $ent.Silindi="Evet"
}
Else {
    If($mobile.DeviceAccessState -eq "Allowed") {
        Write-Host $userdn `t $mobile.DeviceUserAgent `t $easstate.LastSuccessSync " Allowed listesine ekleniyor" -ForegroundColor Green
        $ent.LastSuccessSync=$easstate.LastSuccessSync
        Set-CASMailbox -Identity $userdn -ActiveSyncAllowedDeviceIDs @{add=$deviceid}   # koyup ilk önce çalışıtabilirsin
        $ent.Silindi="Hayır"
        }
        Else {
        $ent.DeviceAccessState=$mobile.DeviceAccessState
        $ent.Silindi="Evet"
        }
    }
 
 
    $rap+=$ent
}
 
$rap | Export-Csv .\easdevices.csv -Encoding UTF8

Last updated