I noticed that the folder names in your example could have a lot more changing
in them than the date. This code should add "BLOCKED_" to the beginning of
every file or folder that begins with "Microsoft.3DBuilder".
$items = Get-ChildItem -Path C:\Temp
$items = $items | Where-Object {$_ -like "Microsoft.3DBuilder*"}
foreach ($item in $items) {
$item | Rename-Item -NewName "BLOCKED_$($item.Name)"
}
- Stephen
From: [email protected] [mailto:[email protected]] On
Behalf Of James Rankin
Sent: Monday, April 18, 2016 5:14 PM
To: [email protected]
Subject: [NTSysADM] RE: Help with PowerShell
Thanks! Will give that a go tomorrow and see how far I get...
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Joseph L. Casale
Sent: 18 April 2016 22:08
To: [email protected]<mailto:[email protected]>
Subject: [NTSysADM] RE: Help with PowerShell
Sure,
You could pattern match then rename each.
PS C:\Data\test> gci 'Microsoft.3DBuilder_*_neutral_~_8wekyb3d8bbwe'
Directory: C:\Data\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 4/18/2016 3:06 PM
Microsoft.3DBuilder_10.10.11.1_neutral_~_8wekyb3d8bbwe
d----- 4/18/2016 3:06 PM
Microsoft.3DBuilder_10.9.50.0_neutral_~_8wekyb3d8bbwe
So, continue with that, either accumulate the result set and loop over them, or
use a pipeline and perform the rename...
jlc
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of James Rankin
Sent: Monday, April 18, 2016 2:44 PM
To: [email protected]<mailto:[email protected]>
Subject: [NTSysADM] Help with PowerShell
I come here once more with my PowerShell issues... :)
I want to rename a bunch of folders from a script (80+). They all have names
which can change slightly. For instance, one is
Microsoft.3DBuilder_10.9.50.0_neutral_~_8wekyb3d8bbwe
But this could change to, for instance
Microsoft.3DBuilder_10.10.11.1_neutral_~_8wekyb3d8bbwe
at any given moment.
Is there any way I could run a PowerShell command to rename a bunch of folders
but use a wildcard in the rename syntax (both for source and destination)? That
is
Microsoft.3DBuilder_*_neutral_~_8wekyb3d8bbwe would rename to
BLOCKED_Microsoft.3DBuilder_*_neutral_~_8wekyb3d8bbwe
Obviously the wildcard in the renamed folder could simply be the same pattern
as found in the original name.
Hope this is a little clearer than mud
James Rankin
EUC Director | HTG TaloSys | 07809 668579 |
[email protected]<mailto:[email protected]>
One Trinity Green, Eldon Street, South Shields, Tyne & Wear, NE33 1SA
Tel: 0191 481 3489
Email address: [email protected]<mailto:[email protected]>
Website: www.talosys.co.uk<http://www.talosys.co.uk>
[phpy9YoGNAM]