Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Creating a PSUserAgent for Microsoft Office Outlook

$
0
0

So, I am currently trying to retrieve information via "Invoke-WebRequest" from Office 365's autodiscover (https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml). My code currently returns the "600: Invalid Request" error code, which for usual sys administration you'd just go, yep, that means Office 365 autodiscover is working, however I want to retrieve the XML information, and use it to create a .prf file, to then create a mail profile. There seems to be useful bits and pieces across the web for doing this kind of thing via C#, but PowerShell is my choice of tool!

My Current code is:

$uri ="https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml"[xml]$AutodiscoverReq =Invoke-WebRequest $uri -Method post -ContentType"text/xml"-Credential $cred 
$AutodiscoverReq.InnerXML

By monitoring traffic, I have found that I also need to use the User Agent for Microsoft Office Outlook, which looks something like this:

MicrosoftOffice/15.0(Windows NT 6.2;MicrosoftOutlook15.0.4693;Pro)

From my research, I have found that PowerShell current has in-built User Agents, I have included the commands I have run and the results below:

Command:

[Microsoft.PowerShell.Commands.PSUserAgent].GetProperties()|Select-ObjectName,@{n='UserAgent';e={[Microsoft.PowerShell.Commands.PSUserAgent]::$($_.Name)}}

Result:

NameUserAgent-------------InternetExplorerMozilla/5.0(compatible; MSIE 9.0;Windows NT;Windows NT 10.0; en-GB)FireFoxMozilla/5.0(Windows NT;Windows NT 10.0; en-GB)Gecko/20100401Firefox/4.0ChromeMozilla/5.0(Windows NT;Windows NT 10.0; en-GB)AppleWebKit/534.6(KHTML, like Gecko)Chrome/7.0.500.0Safari/534.6OperaOpera/9.70(Windows NT;Windows NT 10.0; en-GB)Presto/2.2.1SafariMozilla/5.0(Windows NT;Windows NT 10.0; en-GB)AppleWebKit/533.16(KHTML, like Gecko)Version/5.0Safari/533.16

Command:

[Microsoft.PowerShell.Commands.PSUserAgent].GetProperties()

Result:

MemberType:PropertyName:InternetExplorerDeclaringType:Microsoft.PowerShell.Commands.PSUserAgentReflectedType:Microsoft.PowerShell.Commands.PSUserAgentMetadataToken:385876515Module:Microsoft.PowerShell.Commands.Utility.dllPropertyType:System.StringAttributes:NoneCanRead:TrueCanWrite:FalseGetMethod:System.String get_InternetExplorer()SetMethod:IsSpecialName:FalseCustomAttributes:{}MemberType:PropertyName:FireFoxDeclaringType:Microsoft.PowerShell.Commands.PSUserAgentReflectedType:Microsoft.PowerShell.Commands.PSUserAgentMetadataToken:385876516Module:Microsoft.PowerShell.Commands.Utility.dllPropertyType:System.StringAttributes:NoneCanRead:TrueCanWrite:FalseGetMethod:System.String get_FireFox()SetMethod:IsSpecialName:FalseCustomAttributes:{}MemberType:PropertyName:ChromeDeclaringType:Microsoft.PowerShell.Commands.PSUserAgentReflectedType:Microsoft.PowerShell.Commands.PSUserAgentMetadataToken:385876517Module:Microsoft.PowerShell.Commands.Utility.dllPropertyType:System.StringAttributes:NoneCanRead:TrueCanWrite:FalseGetMethod:System.String get_Chrome()SetMethod:IsSpecialName:FalseCustomAttributes:{}MemberType:PropertyName:OperaDeclaringType:Microsoft.PowerShell.Commands.PSUserAgentReflectedType:Microsoft.PowerShell.Commands.PSUserAgentMetadataToken:385876518Module:Microsoft.PowerShell.Commands.Utility.dllPropertyType:System.StringAttributes:NoneCanRead:TrueCanWrite:FalseGetMethod:System.String get_Opera()SetMethod:IsSpecialName:FalseCustomAttributes:{}MemberType:PropertyName:SafariDeclaringType:Microsoft.PowerShell.Commands.PSUserAgentReflectedType:Microsoft.PowerShell.Commands.PSUserAgentMetadataToken:385876519Module:Microsoft.PowerShell.Commands.Utility.dllPropertyType:System.StringAttributes:NoneCanRead:TrueCanWrite:FalseGetMethod:System.String get_Safari()SetMethod:IsSpecialName:FalseCustomAttributes:{}

My Question is, how can I create a PSUserAgent object myself for outlook? And use it to retrieve the information I need?

If anyone can see any issues with what I'm attempting or has any advice, that would be greatly appreciated.


Viewing all articles
Browse latest Browse all 6937

Trending Articles