param($BriefingID) $sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);' Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32 Function ExistItem ($BriefingID, $OneNoteFilePath, $OneNoteHttpPath, $OneNoteMasterPath, $OneNoteParentPath) { $pathfound = Test-Path $OneNoteFilePath IF (-not $pathfound) { write-host "Warning OneNote not found for briefing" $BriefingID Write-Host "Copying master OneNote from $OneNoteMasterPath to $OneNoteParentPath" New-Item -ItemType Directory -Force -Path "$OneNoteParentPath\Briefing OneNote" Copy-Item "$OneNoteMasterPath\*" "$OneNoteParentPath\Briefing OneNote" # CreateShortcut $OneNoteMasterPath $OneNoteHttpPath } $pathfound = Test-Path $OneNoteFilePath IF ($pathfound) { Write-Host "Successfully found a OneNote file for briefing" $BriefingID $Found = $TRUE } ELSE { $Found = $FALSE } Return $Found } Function CreateShortcut ($OneNoteMasterPath,$OneNoteHttpPath) { $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$OneNoteMasterPath\Use this link to access your digital whiteboard.lnk") $Shortcut.TargetPath = "$OneNoteHttpPath" $Shortcut.Save() } # Here is where the main code starts $BriefingID = "72023" $OneNoteFilePath = "\\myebcweb1@8095\ebc_briefing\$BriefingID\Briefing OneNote\Welcome%20to%20the%20EBC.one" $OneNoteHttpPath = "http://myebc:8095/ebc_briefing/$BriefingID/Briefing%20OneNote/Welcome%20to%20the%20EBC.one" $OneNoteMasterPath = "\\myebcweb1@8095\ebc_briefing\$BriefingID\OneNoteMaster" $OneNoteParentPath = "\\myebcweb1@8095\ebc_briefing\$BriefingID" $Found = ExistItem $BriefingID $OneNoteFilePath $OneNoteHttpPath $OneNoteMasterPath $OneNoteParentPath IF ($Found) { Write-Host "Launching OneNote with your file $OneNoteHttpPath" start-process onenote.exe -ArgumentList $OneNoteHttpPath -WindowStyle Maximized start-sleep 2 $hwnd = @(Get-Process "OneNote")[0].MainWindowHandle # Restore window [Win32.NativeMethods]::ShowWindowAsync($hwnd, 1) } ELSE { Write-Host "Sorry, no Onenote file found for briefing $BriefingID" }