iceycode
10/24/2017 - 3:19 AM

Various Windows Commands

A wide variety of Windows system commands, including extensible features found in Pro and Server versions.

 

& scoop install minisign;
# also can use:
& brew install minisign
& choco install minisign
<#
    Commands that changes permissions, for users & groups, as well as 
     files and folders in Windows.# 

Permissions 
  Switch :: Permission
    N    :: Deny all access
    F	 :: Allow full access
   RX    ::	Read and execute access
    R    ::	Read only access
    W    ::	Write only access
    D	 :: Remove user or group for no access
#>

## file w/ extension OR folder path

$FilePath = "D:\Temp\test.txt" #example is file

$FolderPath = "C:\Windows.old" # example (useful also)

## Users, groups, owners

$User = $env:USERNAME.ToString()

$Group = "ADMINISTRATORS"

$Owner = "$($env:USERDOMAIN)\$($User)"


function Set-TakeownFolder([String]$folderFile){
    if ($Group && $User){
        takeown /F "$($folderFile)" /R /D Y
    }
    else{
        $user = Read-Host "Enter user name: "
        $group = Read-Host "Enter group name: "
        
        
        Set-UserOrGroup($user, $group)
        takeown /F "$($folderFile)" /A /R /D V
    }
}

function Set-UserOrGroup([String]$user, [String]$group)
{
    if ($user && !group){
        $User = $user
    }
    else if (!$user -and $_group){
        $Group = $group
    }
    else{
        $User = $user
        $Group = $group
    }
}

function Set-Owner($owner){
    $Owner = $owner
    
} 

<######### File or Folder permissions
 The main parameter is file OR folderPath
#>

 
###############################################
#(To grant currently logged on user ownership of)
takeown /F "$($fileOrfolderPath)"


### Admin group ownership
# To grant administrators group ownership of
takeown /F "file/path/file" /A


### Currently logged in user
# To grant currently logged on user ownership of 
takeown /F "full path of folder or drive\*.file extension"

### Administrators group
# To grant administrators group ownership of)
takeown /F "full path of folder or drive\*.file extension" /A


#### For example:
takeown /F "C:\Windows\*.txt" /A  # Admin Group ownership of all .txt files



################## 
# To grant currently logged on user ownership of

takeown /F "full path of folder or drive" /R /D Y


# To grant administrators group ownership of

takeown /F "full path of folder or drive" /A /R /D Y




<##### EXAMPLES ######
 granting nfile and folder permissions:
#>






function Set-Ownership([bool]$isFile, $pathTo){

    if (!$isFile){
        & takeown /F "$($pathTo)" /A /R /D Y
    }
    else{
        & takeown /F "$($pathTo)" /A /R /D Y
    }
}

#####################

### To Take Ownership of All Files with the same File Extension in a Folder or Drive using ICACLS Command
# To set any user as owner)
icacls "full path of folder or drive\*.file extension" /setowner "$($User)" /T /C


# To set administrators group as owner
icacls "full path of folder or drive\*.file extension" /setowner "$($Group)" /T /C


#### Example
icacls "{$full_path}\*.{$file_extension}" /setowner "NT SERVICE\TrustedInstaller" /T /C


###################### Granting permissions for user or group

# Allow or Deny Permissions for a File in a Command Prompt
icacls "full path of file" /grant "user name or group":switch




# Allow or Deny Permissions for a Folder or Drive in a Command Prompt
icacls "full path of folder or drive" /grant "user name or group":switch /T

################


#

#