Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Saturday, May 30, 2020

To run a script with full admin privileges On UAC-enabled systems using Powershell

On UAC-enabled systems, to make sure a script is running with full admin privileges, add this code at the beginning of your script

param([switch]$Elevated)

function Test-Admin {
  $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

if ((Test-Admin) -eq $false)  {
    if ($elevated)
    {
        # tried to elevate, did not work, aborting
    }
    else {
        Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}

exit
}

'running with full privileges'


Source:https://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator

Tuesday, April 21, 2020

Install powershell 7 on Debian 10

See the version of Debian

lsb_release -a

First I need to access all the commands stored in /usr/local/sbin and /usr/sbin

I need to edit the .bashrc file in my user's home profile and the last two lines at the end

export PATH=$PATH:/usr/local/sbin
export PATH=$PATH:/usr/sbin



save the file 


and 

Source .bashrc

to reload the file to see the change


to use the old ifconfig

sudo apt install net-tools



to see the dynamically generated ip 

ifconfig

I enabled ssh while installing so now using tool like putty I can access debian from outside

Now let me install cshell zshell and korshell

 sudo apt install csh zsh ksh

Now I am using Debian 10 which I can verify by using  lsb_release -a command

So to install powershell I have to use these commands



# Download the Microsoft repository GPG keys
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh





Source:https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7