Windows OS
--
Questions
--
Followers
Top Experts
I have a strange problem in Powershell. I'm making a small script to rename a folder (found in all users profile) to rename it to their name. below is the script.
$localPath = "c:\Users\$env:UserName\Documents\Adobe\Premiere Pro\13.0\Profile-setup"
if([System.IO.directory]::Exists($localPath)){
Rename-Item -force -Path $localPath -NewName "Profile-$env:UserName"
}
I worked in Powershell ISE, and the script WORKES PERFECT.
when I try to run the PS1 file(using local GPO, Task Scheduler, Startup, batch files), it would not rename it. I set the execution policy to unrestricted
today when investigating more when I open Powershell or CMD (not PowerShell ISE) with administrator privileges and  try to run it using:
powershell -File c:\PS\rename.ps1
it gives me the following errorC:\powershell -File c:\PS\rename.ps1
Rename-Item : Access to the path 'C:\Users\profilesetup\Documents\Adobe\Premiere Pro\13.0\Profile-setup' is denied.
At C:\PS\rename.ps1:7 char:1
+ Rename-Item -force -Path $localPath\Profile-setup -NewName $env:UserN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\Users\profil...0\Profile-setup:String) [Rename-Item], IOException
+ FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
although i'm an in admin account, admin PS and have full access to the folder. As mentioned before, the scipt run using ISE but not in command PS. Any ideas? OS is Windows 10 Pro Educational
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Rename-Item -force -Path $localPath\Profile-setup -NewName $env:UserN ...
doesn't match this (from the script you pasted):
Rename-Item -force -Path $localPath -NewName "Profile-$env:UserName"
What's the actual code?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
@michael: to be clear; each user log in the domain has a folder name Profile-setup (c:\Users\$env:UserName\Do
Rename-Item -force -Path $localPath -NewName "Profile-$env:UserName"
has no problem in ISE, but does not run in PS. I even tried the x86 and x64 of PS with the same result.
the code works! I tried in many accounts, and it just works. but I ran it manually. I will try to deploy on startup or GPO and feedback

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
PowerShell code
$localPath = "c:\Users\$env:UserName\Documents\Adobe\Premiere Pro\13.0\Profile-setup"
if([System.IO.directory]::Exists($localPath)){
#Get-Item -Path "c:\Users\$env:UserName\Documents\Adobe\Premiere Pro\13.0\Profile-setup"
Rename-Item -force -Path $localPath -NewName Profile-$env:UserName
}
batch file code@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%rename.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File """"%PowerShellScriptPath%"""" ' -Verb RunAs}"
pause
you can test it on your machines by creating the folders (Adobe\Premiere Pro\13.0\Profile-setup) in your documents folder. one you run the script, it should be renamed from profile-setup to profile-yourusername






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I recommend  to run SysInternals ProcMon with a filter of "path", "contains" , "profile-" (or more restrictive), and only the file monitoring enabled, then run the script and see what is reported.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Windows OS
--
Questions
--
Followers
Top Experts
This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.
