morejava Posted November 12, 2019 Posted November 12, 2019 Hey all! I'm trying to figure out how to create a powershell script that would run the following. Any help would be super appreciated! Set-Location $env:USERPROFILE\Desktop\VideoPull\ $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" ..\..\ffmpeg.exe -f concat -i mylist.txt -c copy ..\$segmentName.ts }
morejava Posted November 12, 2019 Author Posted November 12, 2019 I tried taking a crack at it with this.... expandcollapse popup#RequireAdmin Local $sCommand = 'PowerShell.exe ' ;~ Reinstall and Re-Register All Windows Apps for All Accounts ;~ $sCommand &= 'Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}' ;~ Using the following for testing purposes only $sCommand &= 'Set-Location $env:USERPROFILE\Desktop\VideoPull\' $sCommand &= '$videoDir = Get-ChildItem | where {$_.Attributes -eq 'Directory'} | Select-Object FullName' $sCommand &= 'Write-Output "Switching to Event Folder:" + $videoDir.FullName' $sCommand &= 'Set-Location $videoDir.FullName' $sCommand &= '$a = [regex]"f-(\d{1,4}).ts"' $sCommand &= '$segmentFolders = Get-ChildItem | where {$_.Attributes -eq 'Directory'}' $sCommand &= '$segmentFolders | ForEach-Object {' $sCommand &= 'Write-Output "Switching to Segment Folder: " + $_.FullName' $sCommand &= 'Set-Location $_.FullName' $sCommand &= '$segmentName = $_.Name' $sCommand &= '$text = ''' $sCommand &= '$text | Set-Content 'mylist.txt'' $sCommand &= '$fragments = Get-ChildItem -Include @("*.ts") -Path $_.FullName -Recurse' $sCommand &= '$fragments | ForEach-Object {' $sCommand &= '$b = $a.Match($_.FullName)' $sCommand &= '$order = [int]$b.Groups[1].Value' $sCommand &= 'Write-Output "Fragment # is: $order"' $sCommand &= '$_ | Add-Member -MemberType NoteProperty Order $order' $sCommand &= '}' $sCommand &= ' $fragments | Sort-Object Order | ForEach-Object{' $sCommand &= '$fragText = 'file ''' + $_.BaseName + '.ts'''' $sCommand &= 'Write-Output $fragText' $sCommand &= '$fragText | Add-Content 'mylist.txt'' $sCommand &= '}' $sCommand &= 'Write-Output "Segment name is $segmentName"' $sCommand &= '..\..\ffmpeg.exe -f concat -i mylist.txt -c copy ..\$segmentName.ts' $sCommand &= '}' $sCommand &= '' $sCommand &= '' $sCommand &= 'Stop-Service tiledatamodelsvc' ;~ Last two lines are just so you can see the output $sCommand &= ' ; ' $sCommand &= 'Read-Host -Prompt "Press Enter to exit"' Run($sCommand)
Subz Posted November 12, 2019 Posted November 12, 2019 (edited) Just save it as a .ps1 first then run using Powershell command something like: Edited November 12, 2019 by Subz
morejava Posted November 13, 2019 Author Posted November 13, 2019 Thanks for the reply! If I did do that can I package the ps1 file within the exe? If I can't how can I add the powershell command within the au3? Total noobie here with Autoit. Thanks for the help!
Moderators JLogan3o13 Posted November 13, 2019 Moderators Posted November 13, 2019 Look at FileInstall in the help file, it will allow you to include the .ps1 file in the compiled executable. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
morejava Posted January 9, 2020 Author Posted January 9, 2020 So I'm back to this again. Long break from this. Got the install ps1 file done but the first line of the ps1 file is currently USERPROFILE\Desktop\VideoPull\ I need that VideoPull folder to be something that the user chooses in the Autoit GUI written like this ;SELECT THE FOLDER FUNC _select_folder() $sDir = FileSelectFolder("Choose the folder", "", 0, @ScriptDir) If StringRight($sDir, 1) <> "\" Then $sDir &= "\" If $sDir = "\" Then ToolTip("user abort",0,0) Sleep(500) ToolTip("",0,0) ;RUNNING THE SCRIPT ;$CMD=('cd '& $sDir &' && (FOR /R %G in ("*.ts") DO @echo file 'G') > mylist.txt && (FOR /R %G in ("*.ts") DO @echo file ''%G'') > mylist.txt && %userprofile%\desktop\ffmpeg.exe -f concat -i mylist.txt -c copy '& $sDir &'UPLOAD-THIS-FILE.ts && exit{ENTER}') $folder = @DesktopDir&"\ffmpeg.exe" ;Set folder Elseif $sDir <> "\" Then ShellExecute('PowerShell.exe', '-executionpolicy Bypass -File "C:\Users\Server\Desktop\WindowsPull.ps1"') So the Powershell file is on the desktop. How can I allow the user to choose the folder that the Powershell is going to execute the ps1 (above) on?
Subz Posted January 9, 2020 Posted January 9, 2020 Maybe something like: ShellExecute('PowerShell.exe', '-executionpolicy Bypass -File "' & $sDir & 'WindowsPull.ps1"')
morejava Posted January 9, 2020 Author Posted January 9, 2020 Thanks for the reply Subz! Not really...So the windowspull.ps1 will always be on the desktop. The user needs to be able to select the folder that the Powershellwill execute on. So the folder that the user selects will change the first line of the Powershell... If I could It would be something like this as the first line of the Powershell Set-Location $env:%USERPROFILE%\' & $sDir & ' But I can't put autoit scripting on a Powershell right???
FrancescoDiMuro Posted January 9, 2020 Posted January 9, 2020 @morejava You can use $Args in PowerShell as explained in the link attached, so, you just need to use FileSelectFolder with AutoIt and pass the folder selected by the user to the PowerShell script Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Subz Posted January 9, 2020 Posted January 9, 2020 Or maybe something like: expandcollapse popup_Select_Folder() Func _Select_Folder() Local $sDir = FileSelectFolder("Choose the folder", "", 0, @ScriptDir) If @error Then ToolTip("user abort",0,0) Sleep(500) ToolTip("",0,0) Exit EndIf Local $sFFMPeg = @DesktopDir&"\ffmpeg.exe" Local $sWindowsPull = "" $sWindowsPull &= 'Set-Location "' & $sDir & '"' & @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 &= '..\..\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(@DesktopDir & "\WindowsPull.ps1", 2) FileWrite($hWindowsPull, $sWindowsPull & @CRLF) FileClose($hWindowsPull) If FileExists(@DesktopDir & "\WindowsPull.ps1") Then ShellExecute('PowerShell.exe', '-executionpolicy Bypass -File "' & @DesktopDir & '\WindowsPull.ps1"') EndFunc
morejava Posted January 11, 2020 Author Posted January 11, 2020 😲You did it Subz! Thanks a ton! Francesco, I'm gonna look into that solution also! Thank you both for all the help
morejava Posted January 15, 2020 Author Posted January 15, 2020 (edited) Something strange is happening with this script. 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! Edited January 16, 2020 by morejava
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now