4. Gestión de archivos en PowerShell para administradores de sistemas

Los sistemas de archivos permiten organizar los datos en los dispositivos de almacenamiento siguiendo una serie de normas y restricciones. Un sistema de archivos se implanta después de crear una partición en un dispositivo de almacenamiento (disco duro, USB, CD/DVD, etc.).

La unidad principal de los sistemas de archivos es el archivo, en general, los sistemas operativos distinguen entre estos tipos de archivos:

  • Normales: los archivos pueden contener cualquier tipo de información.
  • Directorios: son archivos que contienen información sobre la organización y estructura de otros archivos.
  • Especiales: estos archivos permiten comunicarse con dispositivos de E/S.

Los archivos tienes propiedades:

  • Nombre: sirve para identificar un archivo.
  • Extensión: la extensión sirve para saber el tipo de programa que lo ejecuta o interpreta.
  • Tipo de archivo: pueden dividirse en normales, directorios o especiales.
  • Ubicación: lugar del sistema de archivos donde se encuentra un archivo.
  • Tamaño: cantidad de bytes que ocupa un fichero en el sistema de archivos.
  • Fecha de creación, modificación y último acceso: para cada archivo indica la fecha en que ha sido creado, modificado y la última vez que se accedió a él.
  • Atributos: son propiedades que permiten asignar características especiales a los archivos.
  • Permisos: se utilizan para permitir o restringir el acceso a los archivos a determinados usuarios o grupos. Los permisos pueden ser para: leer, modificar, eliminar, renombrar, etc.

A continuación se verán las operaciones que se pueden realizar con archivos y directorios.

Archivos

Las operaciones que se pueden realizar con archivos son:

  • Información sobre archivos

  • Crear archivos

  • Almacenar contenido en un archivo

  • Agregar contenido a un fichero

  • Vaciar el contenido de un fichero

  • Ver el contenido de un fichero

  • Importar el contenido de un fichero

  • Importar el contenido de un fichero XML

  • Exportar el contenido a un fichero

  • Exportar el contenido a un fichero XML

  • Copiar archivos

  • Eliminar ficheros

  • Mover archivos

  • Renombrar

  • Imprimir

  • Comprimir

  • Descomprimir

  • Asignar permisos a archivos

Directorios

Las operaciones que se pueden realizar con directorios son:

  • Crear un una carpeta

  • Cambiar de directorio

  • Listar el contenido de un directorio

  • Copiar carpetas

  • Borrar carpetas

  • Mover carpetas

  • Renombrar carpetas

  • Comprimir

  • Descomprimir

  • Permisos

  • Compartir

ADB Shell Commands

The Android Debug Bridge (adb) provides a Unix shell that you can use to run a variety of commands on an emulator or connected device.

 

ADB Shell Commands

http://developer.android.com/intl/es/tools/help/shell.html


 

Issuing Shell Commands

You can use the shell command to issue commands, with or without entering the adb remote shell on the emulator/device. To issue a single command without entering a remote shell, use the shell command like this:

 

List of all attached device

 

Download a specified file from an device to your computer

 

Upload a specified file from your computer to an device

 

List directory contents

 

Change directory

 

Remove files or directories

 

Make directories

 

Create empty file

 

Current working directory location

 

Copy files and directories

 

Move or rename files

 

Starts (restarts) an emulator/device instance

 

Stops execution of an emulator/device instance

 

Prints kernel debugging messages to the screen

 

Show/manipulate routing, devices, policy routing and tunnels

 

Network statistics

 

Network connection tool

 

Test the connection and latency between two network connection

 

Using activity manager (am)

Activity manager (am) tool to perform various system actions, such as start an activity, force-stop a process, broadcast an intent, modify the device screen properties, and more. While in a shell, the syntax is:

Available activity manager commands:

Start an Activity specified by <INTENT>.

Start the Service specified by <INTENT>.

Kill all processes associated with <PACKAGE>

 

Using package manager (pm)

Within an adb shell, you can issue commands with the package manager (pm) tool to perform actions and queries on application packages installed on the device. While in a shell, the syntax is:

Available activity manager commands:

Prints all packages, optionally only those whose package name contains the text in <FILTER>.

Prints all known permission groups

Prints all known permissions, optionally only those in <GROUP>

Prints all features of the system

Prints all users on the system

Installs a package (specified by <PATH>) to the system

 

Taking a device screenshot

The screencap command is a shell utility for taking a screenshot of a device display. While in a shell, the syntax is:

 

Recording a device screen

The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file.

 

List of all the available shell programs

 

More commands

 

Eliminar permisos explícitos

Eliminar permisos explícitos

Permisos no cambiados

Permisos cambiados

Equivalencias entre comandos de red de Windows y Cmdlets de PowerShell

ARP


IPCONFIG


NETSH


NETSTAT


NSLOOKUP


PING


ROUTE


TRACERT

Mover un proceso de una posición de la pantalla a otra

Automatizar tareas (parte 6)

 
Contenido del fichero accionescasa.txt

accionescasacolorear

Dibujo de la casa con color

casadibujadacoloreada

Automatizar tareas (parte 5)

 
Contenido del fichero accionescasa.txt

accionescasa

Dibujo de la casa

casadibujada

File System Security PowerShell Module 3.2.3

Source are available on CodePlex

https://ntfssecurity.codeplex.com/

Download

https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85/file/48905/1/NTFSSecurity%201.3.zip

Introduction

Managing permissions with PowerShell is only a bit easier than in VBS or the command line as there are no cmdlets for most day-to-day tasks like getting a permission report or adding permission to an item. PowerShell only offers Get-Acl and Set-Acl but everything in between getting and setting the ACL is missing. This module closes the gap.

Documentation

For documentation plese refer to:

Comments, feature requests and bug reports are very welcome: raandree@live.com

Installation

Just create the folder „NTFSSecurity“ in one of the standard module folders and copy the files attached in there. The standard module folders are in the environment variable %PSModulePath%, for example C:\Users\\Documents\WindowsPowerShell\Modules.
For example, all the files in the zip file have to be in „C:\Users\raandree\Documents\WindowsPowerShell\Modules\NTFSSecurity“. If you did this then the module should be listed in „Get-Module -ListAvailable“ and can be imported using „Import-Module NTFSSecurity“.

Description

The module provides 10 cmdlets to manage permissions on the file system, like adding and removing ACEs, setting the inheritance, getting the current permissions or even get the effective permissions for a certain user.
The available cmdlets are listed below with a short description. More information can be retreived in the PowerShell using Get-Help.

The name / SID translation is done by the Security2 class:
Security2 1.2.zip

All cmdlets have at least one parameter that supports the pipeline. They all can work with pipeline input coming from Get-ChildItem but some do more with what comes form the pipeline. For excample you can remove permission by piping what Get-Ace returns to Remove-Ace:

The pipeline support can also be used to backup and restore permissions of one or many items:

All cmdlets can handle SIDs and also SamAccountNames. The output contains always both unless a SID is not resolvable.

The types.ps1xml file is extending the common objects with some useful information and the format.ps1xml file formats all the output in almost the same way like the Get-ChildItem output.

By implementing the [Process Privilege http://processprivileges.codeplex.com/] project the cmdlets can activate the required privileges for setting the ownership for example.

Add-Ace

Adds a specific ace to the current object. This can be done in just one line:

Get-Ace

Gives you a list of all permissions . normally you are interested not in the inherited permissions so the switch ExcludeInherited can be useful

Filtering works with Where-Object

Get-OrphanedAce

Lists all permissions that can no longer be resolved. This normally happens if the account is no longer available so the permissions show up as a SID and not as an account name.
To remove all non-resolvable or orphaned permissions you can use the following line. But be very careful with that as maybe the account is not resolvable due to a network problem.

Remove-Ace

Removes the permission for a certain account. As the pipeline is supported it takes also

Get-EffectivePermissions

Shows the permissions an account actually has on a file or folder. If no parameter is specified it shows the effective permissions for the current user. However you can supply a user by using the SID or account name

Get-Inheritance

Shows if inheritance is blocked

Enable-Inheritance

It can be a problem if certain files or folders on a volume have inheritance disabled. Making sure that inheritance is enabled can be done using this cmdlets:

Disable-Inheritance

See Enable-Inheritance

Get-Owner

Shows the owner of a file or folder

Set-Owner

Sets the owner to a specific account like:

More information

https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85