PowerShell and NTFS permissions

from powershell.com

Adding and Resetting NTFS Permissions

Whether you want to add a new NTFS access rule to a file or turn off inheritance and add new rules, here is a sample script that illustrates the trick and can serve you as a template.

The script creates a test file, then defines a new access rule for the current user. This rules allows read and write access. The new rule is added to the existing security descriptor. In addition, inheritance is turned off.

# create a sample file to apply security rules to
$Path = “$env:temp\examplefile.txt”
$null = New-Item -Path $Path -ItemType File -ErrorAction SilentlyContinue

# use current user or replace with another user name
$username = “$env:USERDOMAIN\$env:USERNAME”

# define the new access rights
$colRights = [System.Security.AccessControl.FileSystemRights]’Read, Write’
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount($username)

# create new access control entry
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)

# get existing access control list for a file or folder
$objACL = Get-Acl -Path $Path

# add rule
$objACL.AddAccessRule($objACE)

# disable inheritance (if needed)
$objACL.SetAccessRuleProtection($true, $false)

# apply changed access control list to file
Set-Acl -Path $Path -AclObject $objACL

# show file in the File Explorer
explorer.exe “/SELECT,$Path”

Once completed, the script opens the test file in the File Explorer and selects it. You can then right-click the file and choose Properties > Security to view the new settings.

To find out the available access rights, in the ISE editor type in this line:

[System.Security.AccessControl.FileSystemRights]::

This will automatically open the context menu and lists all available settings.

Find cpu information in linux via script

ssh root@server.corp.com "bash -s" /tmp/server_cpu.txt

insert less than and greater symbols that include getcpu.sh after "bash -s" above

Save the following as getcpu.sh

cat /proc/cpuinfo | \
awk -v FS=':' ' \
/^physical id/ { if(nb_cpu<$2) { nb_cpu=$2 } } \
/^cpu cores/ { if(nb_cores<$2){ nb_cores=$2 } } \
/^processor/ { if(nb_units<$2){ nb_units=$2 } } \
/^model name/ { model=$2 } \
\
END{ \
nb_cpu=(nb_cpu+1); \
nb_units=(nb_units+1); \
\
print "CPU model:",model; \
print nb_cpu,"CPU,",nb_cores,"physical cores per CPU, total",nb_units,"logical CPU units" \
}'