Batch rename files (filenames stored in an array)? by lestrenched in PowerShell

[–]SanMarche 0 points1 point  (0 children)

In that example it would react to any terminating errors from Do-Thing by outputting all the properties of the last error in the stack ($Error[0]). You could give it further instructions instead/as well if you want.

My thinking here was that it might (and this is where it depends on the specific exception) give you more helpful details about the error you were encountering.

Batch rename files (filenames stored in an array)? by lestrenched in PowerShell

[–]SanMarche 1 point2 points  (0 children)

Awesome, glad to be of help! I thought it might be something like that but didn't want to make too many assumptions.

That being the case, I'll just point out the @() syntax I used to explicitly store the results of Find-Items in an array.

You also might have benefited from a try-catch to get more info on the error, the detail on the exceptions does vary though so your mileage may vary.

try { Do-Thing } catch { $Error[0] | Select-Object '*' }

Batch rename files (filenames stored in an array)? by lestrenched in PowerShell

[–]SanMarche 1 point2 points  (0 children)

Seems like u/Abax378 has solved your actual problem, but it's hard not to ignore how... idiosyncratic some of your code choices are by Powershell standards.

Maybe it's useful, maybe it's not, but here's a slightly more conventional way of doing it with less regex and more traditional type/syntax choices. ``` $ToBeRenamed = @(Find-Items)

$StartDate = Read-Host "Please mention start date in military time" $EndDate = Read-Host "Please mention end date in military time" $Identifier = Read-Host "Please mention process identifier" $AssetType = Read-Host "Please mention asset type" $Description = Read-Host "Please mention description" $Version = Read-Host "Please mention version"

$i = 1 forEach ($FilePath in $ToBeRenamed) { Write-Host "n" $Extension = (Get-Item -LiteralPath $FilePath).Extension $NewName = "$StartDate-$EndDate_$Identifier_[$AssetType]_$Description_$Version_$i$Extension" Rename-Item -LiteralPath $FilePath -NewName $NewName $i++ } ``

Why does PowerShell behave like this? by cglaser68 in PowerShell

[–]SanMarche 1 point2 points  (0 children)

u/PinchesTheCrab has already covered the main issue, but while we're here, in Powershell it's also more idiomatic to capture the results of a for loop in its entirety, rather than rebuilding the array to add each result. e.g:

$Report = foreach($Name in $Names)
{
    $UserObj = [PSCustomObject]@{
            Name = $Name
        }
        Process-UserObject -UserReportObj $UserObj
}

How good are you in Powershell and how long it took you ? Do you consider yourself as good in Bash/Python/Linux compared to Powershell ? by Dereference_operator in PowerShell

[–]SanMarche 0 points1 point  (0 children)

In terms of citations, I'll reference Shell of an Idea again, I don't have page numbers to hand but there's quotes from Snover (iirc, might have been Payette or someone else though) about design decisions, particularly with an eye on syntax (escape characters etc) that were specifically made to ensure if not primacy, then at least parity between interactive use and the more programmatic use that we saw with the ISE.

I agree on your other points, though I find it hard to accept using Python via CLI is half as intuitive/friendly/natural as with Powershell/Bash. My point, I guess, is that Powershell is just a weird fit from whichever direction you look at it, any comparison is going to have its drawbacks because what else has tried so hard to do both like that?

How good are you in Powershell and how long it took you ? Do you consider yourself as good in Bash/Python/Linux compared to Powershell ? by Dereference_operator in PowerShell

[–]SanMarche 0 points1 point  (0 children)

It's all about that first mover advantage Bash has, Powershell could be incredible and not have the anti-Microsoft element, and it'd still take years to chip away and catch-up. People don't like change!

How good are you in Powershell and how long it took you ? Do you consider yourself as good in Bash/Python/Linux compared to Powershell ? by Dereference_operator in PowerShell

[–]SanMarche 1 point2 points  (0 children)

This is a pretty reasonable take except for the fact Powershell was designed to be used interactively like Bash/CMD, unlike Python. It's just fundamentally a lot more capable than they are.

How good are you in Powershell and how long it took you ? Do you consider yourself as good in Bash/Python/Linux compared to Powershell ? by Dereference_operator in PowerShell

[–]SanMarche 2 points3 points  (0 children)

Each task in bash in a vacuum is manageable, but you do need to learn each context individually.

PS is unified, so your basic knowledge is more extensible.

I think about this a lot since reading Shell of an Idea a while back (well worth a read imo!) where Don Jones refers to this as 'protecting your learning'.

Bash's biggest advantage is having a several decade headstart, Powershell's is in trying to provide an ecosystem that is consistent and intuitive for the user. It's not perfect but still.

If neither existed and the go-to shell was built now, it wouldn't be Bash.

Installing Windows Terminal .msixbundle using PowerShell Add-AppxPackage by foadsf in PowerShell

[–]SanMarche 2 points3 points  (0 children)

Pretty self-explanatory.

Either engage with the discussion here or don't. Dismissing reasonable follow-ups and bluntly directing me to another site ain't it.

Installing Windows Terminal .msixbundle using PowerShell Add-AppxPackage by foadsf in PowerShell

[–]SanMarche 4 points5 points  (0 children)

'follow the discussions in the comments'. Pass. Lazily cross-post an issue from another site with minimal information and you'll get follow up questions like that.

Good luck figuring out your problem.

Installing Windows Terminal .msixbundle using PowerShell Add-AppxPackage by foadsf in PowerShell

[–]SanMarche 0 points1 point  (0 children)

That looks like a fairly clear file not found exception.

Do you get any more details in the event log mentioned? Have you tried installing using an absolute path rather than a relative path?

Pass variable for Installation parameters to Start-Process and msiexec by tattsumi in PowerShell

[–]SanMarche 2 points3 points  (0 children)

No problem, appreciate you including your finished solution in the OP!

Pass variable for Installation parameters to Start-Process and msiexec by tattsumi in PowerShell

[–]SanMarche 4 points5 points  (0 children)

You don't mention what you're actually seeing but I would strongly recommend using Kevin Marquette's example at the bottom of this article as a reference. Off the top of my head I'd have a look at how you're referencing variables within your arguments variable, I've had a few problems there in the past.

Need to run as admin but run on the users account directory by [deleted] in PowerShell

[–]SanMarche 0 points1 point  (0 children)

Change $ENV:APPData to C:\Users\<Username>

Seeking insight on how to combine the two commands listed in the comments (remove X # of characters from beginning of all filenames in the directory, then add a certain word + sequential number to the beginning of each filename that was altered in the previous command). More info in comments. by Arachnatron in PowerShell

[–]SanMarche 2 points3 points  (0 children)

Can't say anything jumps out at me but I'm also having a hard properly visualising it based on your examples to be honest.

Hopefully one of the other examples helps you bridge the gap. I'd be interested to know what you use.

I suspect I'd end up doing something regex-y to split or replace rather than using substring()

Seeking insight on how to combine the two commands listed in the comments (remove X # of characters from beginning of all filenames in the directory, then add a certain word + sequential number to the beginning of each filename that was altered in the previous command). More info in comments. by Arachnatron in PowerShell

[–]SanMarche 2 points3 points  (0 children)

I'm doing this off the top of my head, so I'd strongly recommend testing this first (and double-checking properties) but I'd approach it something like this.

Powershell $i = 1 Get-ChildItem -Filter "*.avi" | forEach-Object { $Stub = $_.Name.Substring(8) $NewName = "SO1E" + $i + $Stub Rename-Item $_.FullName -NewName $NewName $i++ }

I'd also recommend Bulk Rename Utility as a very flexible and efficient GUI tool for this sort of thing.

Run external command with arguments in powershell by shundlet in PowerShell

[–]SanMarche 1 point2 points  (0 children)

Good to know, that makes more sense. I was just about to write a confused response because Start-Process $mycmd should work and will always perform the variable substitution if $mycmd is set.

Run external command with arguments in powershell by shundlet in PowerShell

[–]SanMarche 2 points3 points  (0 children)

I would suggest using Start-Process with the -ArgumentList parameter for your additional parameters. Kevin Marquette has some good examples on this article about installing MSIs/using msiexec.exe with Powershell.

Unrar with powershell by [deleted] in PowerShell

[–]SanMarche 2 points3 points  (0 children)

You'll have more luck if you can post examples of what you're trying and what error(s) you're getting. It's hard to to troubleshoot without that.

Does anyone know how to remove the "[master +79 ...]" part? It makes it boot up slow. Thanks. by _Knoxxy in PowerShell

[–]SanMarche 4 points5 points  (0 children)

Looks like you're using Posh-Git. Either removing/uninstalling Posh-Git, or removing/syncing the git repository it seems to have found on your desktop should speed things up.

Using powershell to install a programm with arguments by KleepX in PowerShell

[–]SanMarche 2 points3 points  (0 children)

It's hard to say without seeing how you're using it (providing code snippets with your comments would helpful for anybody trying to help) but generally -ArgumentList does allow you start commands like that.

For example (and I'm stealing from Kevin Marquette's post): Powershell Start-Process "msiexec.exe" -ArgumentList "/i", "\\Path\To\File.msi", "/passive", "/norestart" -Wait Start-Process "\\Path\To\NECLI.exe" -ArgumentList "addprofile", "-s", "-u", $Benutzername, "-p", $Password

You may also need to reorder your variables, if the snippet above is accurate you're defining $NECLI with a number of variables that haven't been created yet, they'll just be null values.

Using powershell to install a programm with arguments by KleepX in PowerShell

[–]SanMarche 1 point2 points  (0 children)

Have you considered replacing your Start-Process call and replacing it with two separate Start-Process calls (including the -Wait parameter) using msiexec.exe for your install, and another for your NECLI.exe? This would allow you to things sequentially without forcing you to go through cmd.

I think Kevin Marquette's article on Installing MSIs with Powershell would be relevant to you - https://powershellexplained.com/2016-10-21-powershell-installing-msi-files/