Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Running PowerShell Script From Sent To Menu Not Working

$
0
0

I have a PowerShell script that adds a prefix to my files based on a given range but when I try to run it using the Sent To context menu I get the following error “You must provide a value expression on the right-hand side of the ‘%’ operator. At line:1 char:22” Any ideas on how to correct this? I am using PowerShell 2.0 and I have very little knowledge of scripting. I had some help with the code. I used this link to setup the Sent To: http://tomtalks.uk/2014/04/powershell-script-right-click-send-to-copy-ps1-to-txt/

[CMDLETBINDING()] PARAM( [Parameter(Mandatory=$true)] $Path ) $Directory = "$Pathtest.txt" $regex_LO = "^[0-1][0-6][0-5][0-9][0-9][0-9][0-9][0-9]" $regex_HI = "^[1-9][6][6-9][0-9][0-9][0-9][0-9][0-9]|^[1-9][7-9][0-9][0-9][0-9][0-9][0-9][0-9]" Get-ChildItem -Path $Path | %{ if($_.name -notmatch '^LO|^HI'){ if($_.name -match $regex_LO){ $newname = "LO" + $Matches.Values Move-Item -Path $_.FullName -Destination ($_.FullName -replace $Matches.Values,$newname) } elseif($_.name -match $regex_HI){ $newname = "HI" + $Matches.Values Move-Item -Path $_.FullName -Destination ($_.FullName -replace $Matches.Values,$newname) } } elseif($_.name -match '^HI'){ if(($_.name -replace '^HI') -match $regex_LO){ $newname = $_.name -replace '^HI','LO' $destination = $_.FullName -replace $_.name, $newname Move-Item -Path $_.FullName -Destination $destination } } elseif($_.name -match '^LO'){ if(($_.name -replace '^LO') -match $regex_HI){ $newname = $_.name -replace '^LO','HI' $destination = $_.FullName -replace $_.name, $newname Move-Item -Path $_.FullName -Destination $destination } } } 

Thanks in advance.

submitted by /u/ShawnnyCanuck
[link] [comments]

The post Running PowerShell Script From Sent To Menu Not Working appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images