Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.69 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Powershell 2.0 sudo limitations
  2. # Trigger UAC to elevate the supplied command
  3. function Elevate-Process() {
  4.     if($args.Length -eq 0) {
  5.         error ('USAGE: ' + $MyInvocation.InvocationName + ' <executable> [arg1 arg2 arg3 ...]');
  6.     } else {
  7.         try {
  8.             if($args.Length -eq 1) {
  9.                 Start-Process $args[0] -Verb RunAs;
  10.             } else {
  11.                Start-Process $args[0] -ArgumentList $args[1..$args.Length] -Verb RunAs;
  12.             }
  13.         } catch {
  14.             error $_.Exception.Message;
  15.         }
  16.     }
  17. }
  18.  
  19. # Display pretty-formatted error messages
  20. function error() {
  21.     # Validate function parameters
  22.     Param(
  23.         [Parameter(Mandatory=$true)]
  24.         [ValidateScript({$_.GetType().Name -eq 'String'})]
  25.         $sMessage
  26.     );
  27.  
  28.     Write-Host $sMessage -BackgroundColor Yellow -ForegroundColor Red;
  29. }
  30.  
  31. # Set aliases
  32. set-alias sudo Elevate-Process;
  33.        
  34. sudo Copy-Item '.standard_menu.ini' 'C:Program Files (x86)Operaui';
  35. #sudo [System.IO.File]::Copy '.webmailproviders.ini' 'C:Program Files (x86)Operadefaultswebmailproviders.ini' $true;
  36.  
  37. Write-Host 'Press any key to exit...';
  38. $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null;
  39.        
  40. Set-Location : A positional parameter cannot be found that accepts argument &#39;Customizations&#39;.
  41. At line:1 char:16
  42. + & {Set-Location <<<<  C:UsersEricDocumentsOpera Customizations; cp .standard_menu.ini C:Pro
  43. gram Files (x86)Operauistandard_menu.ini}
  44.     + CategoryInfo          : InvalidArgument: (:) &#91;Set-Location&#93;, ParameterBindingException
  45.     + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocatio
  46.    nCommand
  47.        
  48. sudo xcopy '.standard_menu.ini' 'C:Program Files (x86)Operaui';