Upload to OneDrive via BITS - powershell

I'm trying to submit a file to OneDrive using BITS.
I found an article on this here: https://msdn.microsoft.com/en-us/library/dn858877.aspx; but I was hoping PowerShell's native Start-BitsTransfer method could save me some effort. However that article implies that OneDrive supports BITS uploads; so things are promising.
$source = '\\myFileServer\Backups\SqlServerDbBackup.bak' #3.2GB file
$destination = 'https://myCompany.sharepoint.com/personal/my_account/Documents/SqlServerDbBackup.bak'
$cred = get-credential #here I enter the same credentials I use to access the site
Start-BitsTransfer -Source $source -Destination $destination -TransferType Upload -Credential $cred
When I run the above code the progress bar briefly pops up, then an error appears. Full output (including credentials prompt) below:
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Start-BitsTransfer : HTTP status 501: The server does not support the functionality required to fulfill the request.
At line:8 char:1
+ Start-BitsTransfer -Source $source -Destination $destination -TransferType Uploa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-BitsTransfer], Exception
+ FullyQualifiedErrorId : StartBitsTransferCOMException,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand
Has anyone attempted this before / any ideas whether it's possible to perform an upload to OneDrive using start-bitstransfer?

It looks like you're trying to upload to OneDrive for Business. The MSDN article you found applies to personal OneDrives; BITS isn't supported in OneDrive for Business. Although you can't use Start-BitsTransfer, you can find info about the new upload API's here, which work for both personal and business OneDrives.

Related

powershell returned an error:(403) WebException using New-pnpList

I had my PS script running the other day and created a new list with a single field with no issues. Was able to view the list in the Site Contents lib.
Today, it's not working. I tried running the PS code below and then resorted to running the new-pnplist code at the command line...got the same error which is shown below.
I'm using the Global admin account. Using version 3.13.19 SharePointPNPPowerShellOnline. Executed the commands from Powershell ISE which is what I did the other day when it worked. And, I was able to connect successfully using the Connect-sposervice command.
Error:
new-pnplist -Template GenericList -Title 'TestPNP2'
new-pnplist : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ new-pnplist -Template GenericList -Title $ListName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [New-PnPList], WebException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Lists.NewList
Code:
$TargetListURL="https://<my sharepoint.com>/sites/CKCDemo"
$ListName="TESTPNP2"
Connect-PnPOnline -url $TargetListURL -CurrentCredentials
New-PnPList -Template GenericList -Title $ListName
Add-PnPField -List $ListName -DisplayName "MyTEST" -InternalName "MyTEST" -Type Text -AddToDefaultView
Get-PnPList`
Make sure you have enough permission to create a list in this site. You could try to go to the site directly, check whether you could create a list through ui.
Note: A global admin will not automatically have access to individual sites unless explicitly granted.

Unable to Download Large File From SharePoint Using PowerShell

I'm unable to download certain files from SharePoint. I think it's because of size but not sure. I was able to download a 500M file. I'm on Windows 7. I upgraded PS to 5.1 and installed the SharePointPnPPowerShellOnline module. My SharePoint authentication is based on multi-factor authentication.
Ultimately, I'm looking to create an script and automate it that gets a list of files and their attributes and based on some condition download specific ones. Some will be 5Gig+.
At PS Prompt:
Connect-PnPOnline –Url https://server.sharepoint.com/personal/user –UseWebLogin
Get-PnPFile -Url "Documents/5gig_file.csv" -AsFile
I was able to download other files. When trying this larger file I get error:
At line:1 char:1
+ Get-PnPFile -Url "Documents/5gig_file.csv" -AsFile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-PnPFile], FormatException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.GetFile
Edit - After more searching around I think this may be related to "MemoryStream" limit having to do with Powershell and not anything to do with SharePoint. https://github.com/PowerShell/PowerShell/issues/4129.

How to use Powershell to grant Windows application or executable to use your network profile?

Powershell newbie here. I am learning Powershell (yes, I have been ignoring it all these years) as I have never needed this one particular need of mine. I have looked at PS tutorial sites and, of course, StackOverflow for any tips. Seems like my need is unique.
Short story, how do you execute an application (for example, notepad.exe) on a local machine to open a network shared file but the local machine has a generic logged-on user but the network share requires a privileged user (like mine) to open the file. I want the app/executable to inherit my credentials but not set the local machine itself. I want to run a local app/executable as if I logged on to the local machine with my credentials.
I have read PS can do this exact thing so I have been experimenting with Powershell command line:
start-process "[SOME APP].exe" -FilePath "\DIRECTORY\PATH\WHERE\APP\IS\LOCATED]" -Credential (Get-Credential -Credential "DOMAIN\USERID")
I get an error prompt from the Powershell command line:
start-process : This command cannot be run due to the error: The
system cannot find the file specified. At line:1 char:1
+ start-process "[SOME APP].exe" -FilePath "[\DIRECTORY\PATH\WHERE\APP\IS\LOCATED] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
ommands.StartProcessCommand
I plan on using this Powershell script in my LabVIEW executable to assign the VI (virtual instrument) executable my own network login privilege to transfer files to/fro or modify a text file that resides in the network share.
Thanks for your help guys!
You could do something like the following. All you need to do is change the $app variable to the executable you want and save the script as a PS1 file. Someone can run it by right-clicking and selecting Run with PowerShell or opening a PowerShell console and typing in path\scriptname.ps1.
$App = "c:\windows\system32\notepad.exe"
$Credentials = Get-Credential
$WorkingDir = Split-Path $app
$Exe = Split-Path $app -Leaf
Start-Process -FilePath $Exe -WorkingDirectory $WorkingDir -credential $Credentials

Unable to remove a directory on network drive with PowerShell

I have built a script that removes a user from AD, Exchange, Lync etc. At the end of the script it deletes the users profile-folder and home-directory. The thing is, only the user who is being deleted has the Full Control for the profile-folder, so I need to delete the folder with his/hers credentials.
First I tried this:
Remove-Item -Path \\networkdrive\share$\profilefolder -Recurse -Force -Credential $UsersCredentials
but I got the following error:
Remove-Item : Cannot retrieve the dynamic parameters for the cmdlet. The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.
Then I tried to do it with the New-PSDrive cmdlet:
New-PSDrive -Name F -PSProvider FileSystem -Root \\networkdrive\share$\profilefolder -Credential $UsersCredentials
I get the following error:
New-PSDrive : Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again
I read somewhere that connecting to the network drive with IP-address might solve the error above, but when I tried that, I got a new error:
New-PSDrive : The specified network password is not correct
Do you have any suggestion as to what I could do? My goal is to use the credentials of the person being deleted to remove the folders. My next step is to download the NetApp PowerShell cmdlets and see if I could get the directories removed with those.
Edit: I decided that I would not to try to remove the folder with other credentials, but instead take the ownership, and delete the folder after that. I tried:
takeown /F \\server\share\folder /A /R /D y
But I got the following error:
SUCCESS: The file (or folder): "\\server\share\folder" now owned by the administrators group.
takeown :
At line:1 char:1
+ takeown /F \server\share\folder /A /R /D y
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
ERROR: The data area passed to a system call is too small.
So it seems I am not able to take the ownership, for some reason. Any suggestions how I could proceed from here?
Remove-Item -Path \networkdrive\share`$\profilefolder -Recurse -Force-Credential $UsersCredentials
Escape the $ in path with a backtick ( ` ).

How can I run an Azure powershell cmdlet through a proxy server with credentials?

When I run the following Powershell cmdlet (from the Azure Management Tools Snapin):
get-osversions -subscriptionId **** -certificate (get-item cert:\CurrentUser\MY\******)
I get the following error message:
Get-OSVersions : The remote server returned an unexpected response: (407) Proxy Authenti
cation Required.
At line:1 char:15
+ get-osversions <<<< -subscriptionId * -certificate
(get-item cert:\CurrentUser\MY*****)
+ CategoryInfo : CloseError: (:) [Get-OSVersions], ProtocolException
+ FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.HostedS
ervices.GetOSVersionsCommand
Get-OSVersions : Object reference not set to an instance of an object.
At line:1 char:15
+ get-osversions <<<< -subscriptionId * -certificate
(get-item cert:\CurrentUser\MY***)
+ CategoryInfo : CloseError: (:) [Get-OSVersions], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.HostedS
ervices.GetOSVersionsCommand
It seems that the internet proxy server here is denying the script the access it requires.
I've had a good look around on the internet and it seems that there is no easy way around this problem since this cmdlet does not have a valid "-credentials" or proxy server parameter.
I know there is a 'Get-Credential' cmdlet but I don't think it helps. How would you pass the credential to the Azure cmdlet?
Can anyone think of any way to get around this issue?..
...other than using a different non-proxied internet connection?
I'm stumped.
Many Thanks for your time.
Easier:
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
A few customers I know were successful using the method outlined here (Supporting Basic Auth proxies). If you need other proxy types, it follows the same pattern. The nice thing about this is it does not require changing the cmdlets.