Access to SharePoint Online path via UNC and PowerShell returns 'Cannot find path [path] because it does not exist'

Provencher, John A 1 Reputation point
2022-07-07T12:15:35.637+00:00

This is a recurring issue. I thought I'd found the answer before by ensuring WebClient is running.

Whether I create the Excel object and try to open the workbook or am using Get-ChildItem, the issue exists. Get-ChildItem [Name].sharepoint.com\sites[sitename] will usually return the top level contents of the site but now tells me it does not exist, which it definitely does. It can be accessed via a browser.

WebClient is running and I cannot access the paths I need to. I've been able to before.
I've tried the path with and without '@rithansodo ', which I think I only need to write to files (Excel) in SharePoint.

I tried loading PnP.PowerShell and connecting to the site, which I can do and Get-PnPList returns the lists on the site.

What am I missing? Is this my issue or a SharePoint issue? I do not have access to SharePoint.

The tag says windows-server-powershell but this is run from my workstation.

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
{count} votes

5 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-07-08T07:47:49.82+00:00

    Hi @Provencher, John A
    Please check about root of UNC path according this document. You can emulate by querying the Win32_Share WMI instances on the remote machine:

    foreach($Share in Get-WmiObject Win32_Share |?{$_.Name -not 'IPC$'}){  
        Get-ChildItem "\\$($Share.__SERVER)\$($Share.Name)"  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

  2. Provencher, John A 1 Reputation point
    2022-07-08T11:18:04.55+00:00

    That's not going to work. This is going against SharePoint Online. And these days, it'd be preferred to use Get-CIMInstance instead of Get-WMIObject, no? Regardless, for the same thing I use Get-WMIObject myself - creature of habit.

    I ended up getting this working but I need a scriptable way to ensure it doesn't happen again. The people who use the script in the end are not PowerShell savvy, so to tell them they need to do this or that in order to run it probably won't work. (They are management).

    What I did was import PnP.PowerShell. I connected to the site with -Interactive for the authentication. I still had the same problem. I connected to the site with -UseWebLogin and Get-ChildItem returned the expected results. Results were returned by any site I have access to. This continued to work after rebooting and not loading anything.

    The worst part is, I cannot replicate the problem. It will work for probably about a week and then I'll face this again.

    Is there a way to avoid this issue without people having to Install-Module PnP.PowerShell; Import-Module PnP.PowerShell; Connect-PnPOnline [server][site] -UseWebLogin?

    Granted, that can be done automatically. Would Connect-SPOService from module Microsoft.Online.SharePoint.PowerShell be any more efficient? Honestly, I have the module but have never used it. I always use PnP.PowerShell for what I need to do.

    0 comments No comments

  3. Provencher, John A 1 Reputation point
    2022-07-08T11:54:22.5+00:00

    It looks like Connect-SPOService won't work because it's not a tenant administration site, not to mention I do not have admin access to SharePoint. So nix that.


  4. Provencher, John A 1 Reputation point
    2022-07-18T11:42:30.24+00:00

    I was already using Connect-PnPOnline. I never hard code credentials into a script, and found that while -Interactive is preferential, for some reason it's not giving me access. I have to use -WebLogin, or open a site with Edge. The access lasts about a week before I need to go through it again. In the end, not everyone running the script is PowerShell savvy. I'm trying to maximize what can be done behind the scenes without getting a million 'Why?' questions.

    Thanks for your help.


  5. Provencher, John A 1 Reputation point
    2022-07-25T20:21:39.95+00:00

    Not using C#, I'm using PowerShell, hence the PnP.PowerShell module.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.