Onedrivemapper V3 beta

As of today, V3 of OnedriveMapper is in testing. It features an auto-updater and does native (no internet explorer) authentication.

The auto updater only works for OnedriveMapper Cloud beta testers, after beta OnedriveMapper Cloud will probably be a service where you can manage / control all OnedriveMapper settings as configurations for your organisation(s) centrally. OnedriveMapper Cloud comes as both a ps1 and msi version.

If you’d like to try OnedriveMapper Cloud, contact me.

Setting a Windows Cookie with Powershell (using InternetSetcookie in WinInet)

As I’m trying to improve OnedriveMapper, I’ve been looking into methods to avoid using Browser Emulation to authenticate with Office 365.

This wasn’t difficult, but storing the cookie posed a challenge. There are no available methods in Powershell to do so, thus I went searching until I ran into a post on Stackoverflow that shows how to store a cookie using C#

Since Powershell can eat C#, this ended up being my working code to set a persistent OS cookie from Powershell:

</p>
<p>$source=@&quot;<br />
using System.Runtime.InteropServices;<br />
using System;<br />
namespace Cookies<br />
{<br />
    public static class setter<br />
    {<br />
        [DllImport(&quot;wininet.dll&quot;, CharSet = CharSet.Auto, SetLastError = true)]<br />
        private static extern bool InternetSetCookie(string url, string name, string data);</p>
<p>        public static bool SetWinINETCookieString(string url, string name, string data)<br />
        {<br />
            bool res = setter.InternetSetCookie(url, name, data);<br />
            if (!res)<br />
            {<br />
                throw new Exception(&quot;Exception setting cookie: Win32 Error code=&quot;+Marshal.GetLastWin32Error());<br />
            }else{<br />
                return res;<br />
            }<br />
        }<br />
    }<br />
}<br />
&quot;@</p>
<p>$compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters<br />
$compilerParameters.CompilerOptions=&quot;/unsafe&quot;</p>
<p>Add-Type -TypeDefinition $source -Language CSharp -CompilerParameters $compilerParameters</p>
<p>[DateTime]$dateTime = Get-Date<br />
$dateTime.AddDays(1)<br />
$str = $dateTime.ToString(&quot;R&quot;)</p>
<p>[Cookies.setter]::SetWinINETCookieString(&quot;https://cookieURL&quot;,&quot;cookieNAME&quot;,&quot;value;Expires=$str&quot;)<br />

edit: don’t use the Get-Hotfix PS command before you run above code, for some reason it breaks things.

O365Undo updated for O365 Groups

O365Undo is a great script you can use to roll back actions of your user(s) in Office 365. Most likely, actions your user wasn’t aware of but were actually done by a CryptoLocker or by RansomWare.

These nasty virusses can cause havoc on your mapped or synced Sharepoint Online or Onedrive for Business libraries in the form of file level encryption or file name obfuscation.

This new version also protects Office 365 Groups.

Read more or download the script

Using Powershell to check a user’s tenant logon setting in Office 365 (without logging in)

I was interested in being able to see, for any given email, what type of authentication Microsoft requires for that user. This could be Office 365 (Azure AD) native, ADFS, etc.

Powershell can easily help you out:

<br />
Add-Type -AssemblyName System.Web<br />
$uid = &quot;YOUR EMAIL ADDRESS&quot;<br />
$uidEnc = [System.Web.HttpUtility]::HtmlEncode($uid)<br />
$res = Invoke-WebRequest -Uri https://login.microsoftonline.com -SessionVariable cookies -Method Get -UseBasicParsing<br />
$stsRequest = ($res.InputFields | where {$_.Name -eq &quot;ctx&quot;}).Value<br />
$flowToken = ($res.InputFields | where {$_.Name -eq &quot;flowToken&quot;}).Value<br />
$canary = ($res.InputFields | where {$_.Name -eq &quot;canary&quot;}).Value<br />
$res = Invoke-WebRequest -Uri &quot;https://login.microsoftonline.com/common/userrealm?user=$uidEnc&amp;api-version=2.1&amp;stsRequest=$stsRequest&amp;checkForMicrosoftAccount=false&quot; -WebSession $cookies -Method GET -UseBasicParsing<br />

The response will contain a redirect to another authentication provider (ADFS) or Azure AD Native. This is an example JSON response:

<br />
{&quot;NameSpaceType&quot;:&quot;Managed&quot;,&quot;Login&quot;:&quot;mymailaddress@domain.nl&quot;,&quot;DomainName&quot;:&quot;lieben.nu&quot;,&quot;FederationBrandName&quot;:&quot;Lieben Consultancy&quot;,&quot;TenantBrandingInfo&quot;:null,&quot;cloud_instance_name&quot;:&quot;microsoftonline.com&quot;}<br />

If you also wish to include Microsoft accounts, set the checkForMicrosoftAccount parameter in the second request to true

AzureAD Connect SSO
If you’re using AzureAD Connect SSO, you can use the above to check if this is correctly set in Office 365. The JSON response will contain a propert is_dsso_enabled, which will be set to True