Anthony K O365
asked on
Help in Running Powershell command - Export Profile Photos from Office 365
I get the error after running the command below: (I'm trying to export Profile Photos from Office 365)
At C:\Users\Get_Photos.ps1:7 char:55
+ if (Get-UserPhoto $objUser.UserPrincipalName -eq $null)
+ ~
Missing statement block after if ( condition ).
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingStatementBlock
$objUsers = ipcsv c:\PS\users.csv | select UserPrincipalName
Foreach ($objUser in $objUsers)
{
if (Get-UserPhoto $objUser.UserPrincipalName -eq $null)
write-host $objUser.UserPrincipalName
}
else
{$user = Get-UserPhoto $objUser.UserPrincipalName
$user.PictureData |Set-Content "C:\PS\Photo$($User.Identi ty).jpg" -Encoding byte
}
At C:\Users\Get_Photos.ps1:7 char:55
+ if (Get-UserPhoto $objUser.UserPrincipalName
+ ~
Missing statement block after if ( condition ).
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingStatementBlock
$objUsers = ipcsv c:\PS\users.csv | select UserPrincipalName
Foreach ($objUser in $objUsers)
{
if (Get-UserPhoto $objUser.UserPrincipalName
write-host $objUser.UserPrincipalName
}
else
{$user = Get-UserPhoto $objUser.UserPrincipalName
$user.PictureData |Set-Content "C:\PS\Photo$($User.Identi
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
here is what I get;
At C:\Users\katadmin\Desktop\ O365items\ Get_Photos .ps1:7 char:57
+ if ((Get-UserPhoto $objUser.UserPrincipalName ) -eq $null)
+ ~
Missing statement block after if ( condition ).
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingStatementBlock
At C:\Users\katadmin\Desktop\
+ if ((Get-UserPhoto $objUser.UserPrincipalName
+ ~
Missing statement block after if ( condition ).
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingStatementBlock
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is what I get:
A parameter cannot be found that matches parameter name 'eq'.
+ CategoryInfo : InvalidArgument: (:) [Get-UserPhoto], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Get -UserPhoto
+ PSComputerName : ps.outlook.com
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\katadmin\Desktop\ O365items\ Get_Photos .ps1:6 char:1
+ else {
+ ~~~~
+ CategoryInfo : ObjectNotFound: (else:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
A parameter cannot be found that matches parameter name 'eq'.
+ CategoryInfo : InvalidArgument: (:) [Get-UserPhoto], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Get
+ PSComputerName : ps.outlook.com
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\katadmin\Desktop\
+ else {
+ ~~~~
+ CategoryInfo : ObjectNotFound: (else:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Try this:
Foreach ($objUser in (Import-Csv c:\ps\users.csv)) {
$photo = Get-UserPhoto $objUser.userprincipalname
if ($photo -notlike '*') {
write-host $objUser.UserPrincipalName
}
}
else {
$user = Get-UserPhoto $objUser.UserPrincipalName
$user.PictureData |Set-Content "C:\PS\Photo$($User.Identity).jpg" -Encoding byte
}
ASKER
Excellent! that worked, however, I now get this error: Any thoughts?
Cannot process argument transformation on parameter 'Identity'. Cannot convert value
"@{UserPrincipalName=JDoe@ Domain.com }" to type "Microsoft.Exchange.Config uration.Ta sks.Mailbo xIdParamet er".
Error: "Cannot convert hashtable to an object of the following type:
Microsoft.Exchange.Configu ration.Tas ks.Mailbox IdParamete r. Hashtable-to-Object conversion is not supported in
restricted language mode or a Data section."
+ CategoryInfo : InvalidData: (:) [Get-UserPhoto], ParameterBindin...mationEx ception
+ FullyQualifiedErrorId : ParameterArgumentTransform ationError ,Get-UserP hoto
+ PSComputerName : ps.outlook.com
Cannot process argument transformation on parameter 'Identity'. Cannot convert value
"@{UserPrincipalName=JDoe@
Error: "Cannot convert hashtable to an object of the following type:
Microsoft.Exchange.Configu
restricted language mode or a Data section."
+ CategoryInfo : InvalidData: (:) [Get-UserPhoto], ParameterBindin...mationEx
+ FullyQualifiedErrorId : ParameterArgumentTransform
+ PSComputerName : ps.outlook.com
Ok maybe this then:
Foreach ($objUser in (Import-Csv c:\ps\users.csv)) {
$photo = Get-UserPhoto $($objUser.userprincipalname)
if ($photo -notlike '*') {
write-host $($objUser.UserPrincipalName)
}
}
else {
$user = Get-UserPhoto $($objUser.UserPrincipalName)
$user.PictureData | Set-Content "C:\PS\Photo$($User.Identity).jpg" -Encoding byte
}
ASKER
The command runs, however it doesn't output any data probably b/c of the error statement below:
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\get_photos5.ps1:7 char:1
+ else {
+ ~~~~
+ CategoryInfo : ObjectNotFound: (else:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\get_photos5.ps1:7
+ else {
+ ~~~~
+ CategoryInfo : ObjectNotFound: (else:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
ASKER
I think I need to do further research on the Get-UserPhoto from Office 365. Here is the error I now get. Some of my users have Profile photos stored in Office 365, however I need a way to bypass errors if there is no photo found. You guys have been helpful! I will do further research on this command.
Thank you!
Error on proxy command 'Get-UserPhoto -Identity:'CN=Doe\, Jane,OU=Tenant.onmicrosoft .com,OU=Mi crosoft
Exchange Hosted Organizations,DC=NAMPR07A0 01,DC=prod ,DC=outloo k,DC=com'' to server
SN2PR07MB2655.namprd07.pro d.outlook. com: Server version 15.01.1084.0000, Proxy method PSWS:
Cmdlet error with following error message:
Microsoft.Exchange.Data.St orage.User PhotoNotFo undExcepti on: There is no photo stored here.
at Microsoft.Exchange.Configu ration.Tas ks.Task.Th rowError(E xception exception, ErrorCategory errorCategory, Object
target, String helpUrl)
at Microsoft.Exchange.Configu ration.Tas ks.Task.Wr iteError(E xception exception, ErrorCategory category, Object
target, Boolean reThrow)
at Microsoft.Exchange.Managem ent.Recipi entTasks.G etUserPhot o.ConvertD ataObjectT oPresentat ionObject( IConfigura ble
dataObject)
at Microsoft.Exchange.Configu ration.Tas ks.GetReci pientObjec tTask`2.Wr iteResult( IConfigura ble dataObject)
at Microsoft.Exchange.Configu ration.Tas ks.GetTask Base`1.Wri teResult[T ](IEnumera ble`1 dataObjects)
at Microsoft.Exchange.Configu ration.Tas ks.GetObje ctWithIden tityTaskBa se`2.Inter nalProcess Record()
Thank you!
Error on proxy command 'Get-UserPhoto -Identity:'CN=Doe\, Jane,OU=Tenant.onmicrosoft
Exchange Hosted Organizations,DC=NAMPR07A0
SN2PR07MB2655.namprd07.pro
Cmdlet error with following error message:
Microsoft.Exchange.Data.St
at Microsoft.Exchange.Configu
target, String helpUrl)
at Microsoft.Exchange.Configu
target, Boolean reThrow)
at Microsoft.Exchange.Managem
dataObject)
at Microsoft.Exchange.Configu
at Microsoft.Exchange.Configu
at Microsoft.Exchange.Configu
ASKER
Excellent PS guidelines for a novice like me.
Thank you!
Thank you!
Open in new window