Jump to content
morejava

OneDrive and Powershell script error

Recommended Posts

Something strange is happening with the following script. 

$folder = @TempDir&"\ffmpeg.exe" ;Set folder

    if $sDir <> "\" Then

    Local $sFFMPeg = @TempDir&"\ffmpeg.exe"
    Local $sWindowsPull =""
    $sWindowsPull &= 'Set-Location "' & @TempDir & '"' & @CRLF
        $sWindowsPull &= "$videoDir = Get?-ChildItem | where {$_.Attributes -eq '" & "Directory" & "'} | Select-Object FullName" & @CRLF
        $sWindowsPull &= 'Write-Output "Switching to Event Folder:" + $videoDir.FullName' & @CRLF
        $sWindowsPull &= 'Set-Location $videoDir.FullName' & @CRLF
        $sWindowsPull &= '$a = [regex]"f-(\d{1,4}).ts"' & @CRLF
        $sWindowsPull &= "$segmentFolders = Get-ChildItem | where {$_.Attributes -eq 'Directory'}" & @CRLF
        $sWindowsPull &= '$segmentFolders | ForEach-Object {' & @CRLF
        $sWindowsPull &= 'Write-Output "Switching to Segment Folder: " + $_.FullName' & @CRLF
        $sWindowsPull &= 'Set-Location $_.FullName' & @CRLF
        $sWindowsPull &= '$segmentName = $_.Name' & @CRLF
        $sWindowsPull &= "$text = ''" & @CRLF
        $sWindowsPull &= "$text | Set-Content 'mylist.txt'" & @CRLF
        $sWindowsPull &= '$fragments = Get-ChildItem -Include @("*.ts") -Path $_.FullName -Recurse' & @CRLF
        $sWindowsPull &= '$fragments | ForEach-Object {' & @CRLF
        $sWindowsPull &= '$b = $a.Match($_.FullName)' & @CRLF
        $sWindowsPull &= '$order = [int]$b.Groups[1].Value' & @CRLF
        $sWindowsPull &= 'Write-Output "Fragment # is: $order"' & @CRLF
        $sWindowsPull &= '$_ | Add-Member -MemberType NoteProperty Order $order' & @CRLF
        $sWindowsPull &= '}' & @CRLF
        $sWindowsPull &= ' $fragments | Sort-Object Order | ForEach-Object{' & @CRLF
        $sWindowsPull &= "$fragText = 'file ' + $_.BaseName + '.ts'" & @CRLF
        $sWindowsPull &= 'Write-Output $fragText' & @CRLF
        $sWindowsPull &= "$fragText | Add-Content 'mylist.txt'" & @CRLF
        $sWindowsPull &= '}' & @CRLF
        $sWindowsPull &= 'Write-Output "Segment name is $segmentName"' & @CRLF
        $sWindowsPull &= @TempDir&'\ffmpeg.exe -f concat -i mylist.txt -c copy ..\$segmentName.ts' & @CRLF
        $sWindowsPull &= '}' & @CRLF
        $sWindowsPull &= '' & @CRLF
        $sWindowsPull &= '' & @CRLF
        $sWindowsPull &= 'Stop-Service tiledatamodelsvc' & @CRLF
        $sWindowsPull &= ' ; ' & @CRLF
        $sWindowsPull &= 'Read-Host -Prompt "Press Enter to exit"'
        Local $hWindowsPull = FileOpen(@TempDir&"\WindowsPull.ps1", 2)
        FileWrite($hWindowsPull, $sWindowsPull & @CRLF)
        FileClose($hWindowsPull)
    If FileExists(@TempDir&"\WindowsPull.ps1") Then ShellExecute('PowerShell.exe', '-executionpolicy Bypass -File "'&@TempDir&'\WindowsPull.ps1"')

 

Everything works as intended when the desktop is the true desktop (C:\Users\firstname.lastname\desktop) but when the desktop is mapped to OneDrive (C:\Users\firstname.lastname\OneDrive\desktop) It's like it can't find the ps1 file or something (see error at the end of the post).  For example:  

True desktop

Set-Location "C:\Users\C:\Users\firstname.lastname\Desktop\12-19-2018_13-09-41.135"
$videoDir = Get?-ChildItem | where {$_.Attributes -eq 'Directory'} | Select-Object FullName
Write-Output "Switching to Event Folder:" + $videoDir.FullName
Set-Location $videoDir.FullName
$a = [regex]"f-(\d{1,4}).ts"
$segmentFolders = Get-ChildItem | where {$_.Attributes -eq 'Directory'}
$segmentFolders | ForEach-Object {
Write-Output "Switching to Segment Folder: " + $_.FullName
Set-Location $_.FullName
$segmentName = $_.Name
$text = ''
$text | Set-Content 'mylist.txt'
$fragments = Get-ChildItem -Include @("*.ts") -Path $_.FullName -Recurse
$fragments | ForEach-Object {
$b = $a.Match($_.FullName)
$order = [int]$b.Groups[1].Value
Write-Output "Fragment # is: $order"
$_ | Add-Member -MemberType NoteProperty Order $order
}
 $fragments | Sort-Object Order | ForEach-Object{
$fragText = 'file ' + $_.BaseName + '.ts'
Write-Output $fragText
$fragText | Add-Content 'mylist.txt'
}
Write-Output "Segment name is $segmentName"
C:\UsersC:\Users\firstname.lastname\desktop\ffmpeg.exe -f concat -i mylist.txt -c copy ..\$segmentName.ts
}


Stop-Service tiledatamodelsvc
 ; 
Read-Host -Prompt "Press Enter to exit"

For some reason, a OneDrive mapped Desktop doesn't work:

Set-Location "C:\Users\firstname.lastname\OneDrive\desktop\12-19-2018_13-09-41.135"
$videoDir = Get?-ChildItem | where {$_.Attributes -eq 'Directory'} | Select-Object FullName
Write-Output "Switching to Event Folder:" + $videoDir.FullName
Set-Location $videoDir.FullName
$a = [regex]"f-(\d{1,4}).ts"
$segmentFolders = Get-ChildItem | where {$_.Attributes -eq 'Directory'}
$segmentFolders | ForEach-Object {
Write-Output "Switching to Segment Folder: " + $_.FullName
Set-Location $_.FullName
$segmentName = $_.Name
$text = ''
$text | Set-Content 'mylist.txt'
$fragments = Get-ChildItem -Include @("*.ts") -Path $_.FullName -Recurse
$fragments | ForEach-Object {
$b = $a.Match($_.FullName)
$order = [int]$b.Groups[1].Value
Write-Output "Fragment # is: $order"
$_ | Add-Member -MemberType NoteProperty Order $order
}
 $fragments | Sort-Object Order | ForEach-Object{
$fragText = 'file ' + $_.BaseName + '.ts'
Write-Output $fragText
$fragText | Add-Content 'mylist.txt'
}
Write-Output "Segment name is $segmentName"
C:\Users\firstname.lastname\OneDrive\desktop\ffmpeg.exe -f concat -i mylist.txt -c copy ..\$segmentName.ts
}


Stop-Service tiledatamodelsvc
 ; 
Read-Host -Prompt "Press Enter to exit"

I get this Powershell error:

Get?-ChildItem : The term 'Get?-ChildItem' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\Users\firstname.lastname\OneDrive\desktop\WindowsPull.ps1:2 char:13
+ $videoDir = Get?-ChildItem | where {$_.Attributes -eq 'Directory'} |  ...
+             ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get?-ChildItem:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Switching to Event Folder:
+
Set-Location : Cannot process argument because the value of argument "path" is null. Change the value of argument
"path" to a non-null value.
At C:\Users\firstname.lastname\OneDrive\desktop\WindowsPull.ps1:4 char:1
+ Set-Location $videoDir.FullName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], PSArgumentNullException
    + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SetLocationCommand

Stop-Service : Cannot find any service with service name 'tiledatamodelsvc'.
At C:\Users\firstname.lastname\OneDrive\desktop\WindowsPull.ps1:30 char:1
+ Stop-Service tiledatamodelsvc
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (tiledatamodelsvc:String) [Stop-Service], ServiceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.StopServiceCommand

Press Enter to exit:

Any idea where I've gone wrong or what the error means?  It's just strange that the Powershell script seems to be looking in the right spots but it still doesn't work for OneDrive.  Thank you for your time and help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...