Long time reader but new poster. I've been wrestling with this issue for an entire day and it's driving me nuts. After scouring this site and Google, I'm still stuck. Basically, I can't figure out how to implement a "sudo" in Powershell that works with the Copy-Item CmdLet. Here's my code:
PROFILE.PS1:
# Trigger UAC to elevate the supplied command
function Elevate-Process() {
if($args.Length -eq 0) {
error ('USAGE: ' + $MyInvocation.InvocationName + ' <executable> [arg1 arg2 arg3 ...]');
} else {
try {
if($args.Length -eq 1) {
Start-Process $args[0] -Verb RunAs;
} else {
Start-Process $args[0] -ArgumentList $args[1..$args.Length] -Verb RunAs;
}
} catch {
error $_.Exception.Message;
}
}
}
# Display pretty-formatted error messages
function error() {
# Validate function parameters
Param(
[Parameter(Mandatory=$true)]
[ValidateScript({$_.GetType().Name -eq 'String'})]
$sMessage
);
Write-Host $sMessage -BackgroundColor Yellow -ForegroundColor Red;
}
# Set aliases
set-alias sudo Elevate-Process;
APPLY-INI.PS1:
sudo Copy-Item '.\standard_menu.ini' 'C:\Program Files (x86)\Opera\ui\';
#sudo [System.IO.File]::Copy '.\webmailproviders.ini' 'C:\Program Files (x86)\Opera\defaults\webmailproviders.ini' $true;
Write-Host 'Press any key to exit...';
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null;
When I execute powershell.exe .\apply-ini.ps1, I get the following error:
This command cannot be executed due to the error: The system cannot find the file specified.
I've tried EVERYTHING I could possibly find without any luck. Hopefully someone can point me in the right direction.