Hello All. I want to thank you in advance for your time and assistance. ultimately I would like to run a script (more importantly have helpdesk do it) that removes allowed devices from Quarantine in exchange365. I have been able to piece
scripts together to try to get this accomplished but "need a powershell" expert to fill in the guesses I'm making.
This I have gotten to work to do what we want but only individually so not any help.
$MobileDevice = Get-MobileDevice -Mailbox *USERNAME* -Filter {DeviceAccessState -eq 'Quarantined'}
# allow the device
Set-CASMailbox -Identity *USERNAME* -ActiveSyncAllowedDeviceIDs $MobileDevice.DeviceId
$MobileDevice.DeviceAccessState = 'Allowed'
$MobileDevice.DeviceAccessStateReason = 'Individual'
.
I want to subtitue the *USERNAME*, format 'JDoe' typically, for a variable filled in by a csv file.
So we can get a list of authorized users in that CSV plug it in and run it to allow everyone on the list.
That way if HelpDesk Gets a request, HelpDesk runs the script if they're not enabled they're not on the list and so sorry buddy.
Here's what I've been able to put together.
#CAN I??
# Connecting to O365.
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
# Once connected
Function FileName($initialDirectory){
##----------------------------------------------------------------------------------------------------
## Function: FileName
## Purpose: This function opens up an Open file window for selection.
## .CSV file would contain list of UN JDoe single column titled 'Identity'.
##---------------------------------------------------------------------------------------------------- [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "CSV Files (*.csv)| *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
#END Function FileName
}
#Import the CSV file and set the deviceID column to a variable.
FileName -initialDirectory c:\ | import-csv | ForEach-Object {
$identity = $_.Identity
#Allow that user out of Quarantine
$MobileDevice = Get-MobileDevice -Mailbox $identity -Filter {DeviceAccessState -eq 'Quarantined'}
# allow the device
Set-CASMailbox -Identity $identity -ActiveSyncAllowedDeviceIDs $MobileDevice.DeviceId
$MobileDevice.DeviceAccessState = 'Allowed'
$MobileDevice.DeviceAccessStateReason = 'Individual'
}
This I have gotten to work to do what we want but only individually so not any help.
$MobileDevice = Get-MobileDevice -Mailbox *USERNAME* -Filter {DeviceAccessState -eq 'Quarantined'}
# allow the device
Set-CASMailbox -Identity *USERNAME* -ActiveSyncAllowedDeviceIDs $MobileDevice.DeviceId
$MobileDevice.DeviceAccessState = 'Allowed'
$MobileDevice.DeviceAccessStateReason = 'Individual'
.
I want to subtitue the *USERNAME*, format 'JDoe' typically, for a variable filled in by a csv file.
So we can get a list of authorized users in that CSV plug it in and run it to allow everyone on the list.
That way if HelpDesk Gets a request, HelpDesk runs the script if they're not enabled they're not on the list and so sorry buddy.
Here's what I've been able to put together.
#CAN I??
# Connecting to O365.
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
# Once connected
Function FileName($initialDirectory){
##----------------------------------------------------------------------------------------------------
## Function: FileName
## Purpose: This function opens up an Open file window for selection.
## .CSV file would contain list of UN JDoe single column titled 'Identity'.
##---------------------------------------------------------------------------------------------------- [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "CSV Files (*.csv)| *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
#END Function FileName
}
#Import the CSV file and set the deviceID column to a variable.
FileName -initialDirectory c:\ | import-csv | ForEach-Object {
$identity = $_.Identity
#Allow that user out of Quarantine
$MobileDevice = Get-MobileDevice -Mailbox $identity -Filter {DeviceAccessState -eq 'Quarantined'}
# allow the device
Set-CASMailbox -Identity $identity -ActiveSyncAllowedDeviceIDs $MobileDevice.DeviceId
$MobileDevice.DeviceAccessState = 'Allowed'
$MobileDevice.DeviceAccessStateReason = 'Individual'
}