osiexchange
asked on
Need help with a PS script
Here is the script I am running to extract info about activesync devices:
$Date = Get-Date -uformat "%Y%m%d"
$Logfile = "C:\logs\activesync-all-$d ate.txt
$Lst = Get-CASMailbox -ResultSize Unlimited | Where
{$_.HasActiveSyncDevicePar tnership - eq $True}
ForEach ($CASMbx in $lst) {
$Devices=$Null
$Devices= @Get-ActiveSyncDeviceStati stics -Mailbox $CASMbx.name)
ForEach ($device in $devices) {
$DeviceModel = $Device.DeviceModel
$DeviceType = $Device.DeviceType
$LastSyncTime = $Device.LastSuccessSync
$PhoneNumber = $Device.DevicePhonenumber
$UserAgent = $Device.DeviceUserAgent
Add-Content -path $Logfile "$casmbx.name
|$DeviceModel | $DeviceType | $UserAgent | $LastSyncTime | $PhoneNumber|"
}
}
Getting this error:
Unexpected token 'casmbx' in expression or statement.
At C:\Program Files\Microsoft\Exchange Server\v14\scripts\get-add evices.ps1 :16 char:36
+ Add-Content -path $Logfile "$casmbx <<<< .name
+ CategoryInfo : ParserError: (casmbx:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
I am sure its a minor change but I can't seem to narrow it down.
$Date = Get-Date -uformat "%Y%m%d"
$Logfile = "C:\logs\activesync-all-$d
$Lst = Get-CASMailbox -ResultSize Unlimited | Where
{$_.HasActiveSyncDevicePar
ForEach ($CASMbx in $lst) {
$Devices=$Null
$Devices= @Get-ActiveSyncDeviceStati
ForEach ($device in $devices) {
$DeviceModel = $Device.DeviceModel
$DeviceType = $Device.DeviceType
$LastSyncTime = $Device.LastSuccessSync
$PhoneNumber = $Device.DevicePhonenumber
$UserAgent = $Device.DeviceUserAgent
Add-Content -path $Logfile "$casmbx.name
|$DeviceModel | $DeviceType | $UserAgent | $LastSyncTime | $PhoneNumber|"
}
}
Getting this error:
Unexpected token 'casmbx' in expression or statement.
At C:\Program Files\Microsoft\Exchange Server\v14\scripts\get-add
+ Add-Content -path $Logfile "$casmbx <<<< .name
+ CategoryInfo : ParserError: (casmbx:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
I am sure its a minor change but I can't seem to narrow it down.
ASKER
I tried your script and I am now getting the error below:
Unexpected token 'casmbxname' in expression or statement.
At C:\Program Files\Microsoft\Exchange Server\v14\scripts\get-add evices.ps1 :17 char:40
+ Add-Content -path $Logfile "$casmbxname <<<<
+ CategoryInfo : ParserError: (casmbxname:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
Unexpected token 'casmbxname' in expression or statement.
At C:\Program Files\Microsoft\Exchange Server\v14\scripts\get-add
+ Add-Content -path $Logfile "$casmbxname <<<<
+ CategoryInfo : ParserError: (casmbxname:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hello,
Try this:
JJ
Try this:
$Date = Get-Date -uformat "%Y%m%d"
$Logfile = "C:\logs\activesync-all-$date.txt
$Lst = Get-CASMailbox -ResultSize Unlimited | Where
{$_.HasActiveSyncDevicePartnership - eq $True}
ForEach ($CASMbx in $lst) {
$Devices=$Null
$CASMbxName = $CASMbx.Name
$Devices= Get-ActiveSyncDeviceStatistics -Mailbox $CASMbxName
ForEach ($device in $devices) {
$DeviceModel = $Device.DeviceModel
$DeviceType = $Device.DeviceType
$LastSyncTime = $Device.LastSuccessSync
$PhoneNumber = $Device.DevicePhonenumber
$UserAgent = $Device.DeviceUserAgent
Add-Content -path $Logfile "$($casmbxname) |$($DeviceModel) | $($DeviceType) | $($UserAgent) | $($LastSyncTime) | $($PhoneNumber) |"
}
}
JJ
$Date = Get-Date -uformat "%Y%m%d"
$Logfile = "C:\logs\activesync-all-$d
$Lst = Get-CASMailbox -ResultSize Unlimited | Where
{$_.HasActiveSyncDevicePar
ForEach ($CASMbx in $lst) {
$Devices=$Null
$CASMbxName = $CASMbx.Name
$Devices= Get-ActiveSyncDeviceStatis
ForEach ($device in $devices) {
$DeviceModel = $Device.DeviceModel
$DeviceType = $Device.DeviceType
$LastSyncTime = $Device.LastSuccessSync
$PhoneNumber = $Device.DevicePhonenumber
$UserAgent = $Device.DeviceUserAgent
Add-Content -path $Logfile "$casmbxname
|$DeviceModel | $DeviceType | $UserAgent | $LastSyncTime | $PhoneNumber|"
}
}