
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 1.69 KB | hits: 22 | expires: Never
Powershell 2.0 sudo limitations
# 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;
sudo Copy-Item '.standard_menu.ini' 'C:Program Files (x86)Operaui';
#sudo [System.IO.File]::Copy '.webmailproviders.ini' 'C:Program Files (x86)Operadefaultswebmailproviders.ini' $true;
Write-Host 'Press any key to exit...';
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null;
Set-Location : A positional parameter cannot be found that accepts argument 'Customizations'.
At line:1 char:16
+ & {Set-Location <<<< C:UsersEricDocumentsOpera Customizations; cp .standard_menu.ini C:Pro
gram Files (x86)Operauistandard_menu.ini}
+ CategoryInfo : InvalidArgument: (:) [Set-Location], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocatio
nCommand
sudo xcopy '.standard_menu.ini' 'C:Program Files (x86)Operaui';