Guest User

Untitled

a guest
Sep 30th, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
  2. {
  3. # Relaunch as an elevated process:
  4. Start-Process powershell.exe "-File",('"{0}"' -f (($MyInvocation.PSCommandPath)+$PSCommandPath)) -Verb RunAs
  5. exit
  6. }
  7.  
  8. #Start Excel
  9. $Excel=New-Object -ComObject Excel.Application
  10. #Open File
  11. $FilePath='C:\Path\To\OneDrive - Company Ltd\Desktop\testing.xlsx'
  12. $WorkBook=$Excel.Workbooks.Open($FilePath)
  13. #Make it visible (Just to check what is happening)
  14. $Excel.Visible=$true
Advertisement
Add Comment
Please, Sign In to add comment