26 January 2015

Active Directory schema attribute details

$schema =[DirectoryServices.ActiveDirectory.ActiveDirectorySchema]::GetCurrentSchema()

$schema.FindClass('user').optionalproperties | Where-Object {$_.name -eq 'employeeid'}

11 January 2015

Scheduled jobs in powershell v3

PSScheduledJob is the module name.

Scheduled jobs can be viewed in Task Scheduler GUI.

Scheduled jobs cmdlet can only be used for the path: Microsoft\Windows\PowerShell\ScheduledJobs

SheduledTask module can be used to manage all other scheduled tasks (available only in Windows 8 and Server 2012).

Job definition and output is stored on disk in different files that can be found on:

%UserProfile%\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs\JobName

09 January 2015

About modules in powershell v3

Powershell have two default location in which it search for modules: one for the system and one for the user currently logged on:

  • system: %windir%\System32\WindowsPowerShell\v1.0\Modules
  • user: %UserProfile%\Documents\WindowsPowerShell\Modules
these values are stored in a environment variable $ENV:PSModulePath

Modules from this location will be automatically imported in powershell v3.

Get-Command cmdlet will return commands from imported or modules available in the two paths.

In powershell v3, modules can be imported (or listed) from another computer trough a cimsession or powershell session:

Import-Module -CimSession $session -Name ModuleName

Get-Module -CimSession $session -ListAvailable

PowerShell Web Access

PSWA (PowerShell Web Access) emulates a powershell console in a web browser.

PSWA is a feature (not a role) available only on Windows Server 2012.
It requires web server role (IIS).

Setup steps:

  • install PSWA windows feature
  • install the PSWA web application 
  • add PSWA authorization rules to control and secure access.

06 January 2015

Out-GridView enhancement in powershell v3

In powershell v3 cmdlet Out-GridView had a great enhancement with OutputMode parameter.

When used, this parameter instructs the cmdlet to send the items from the interactive window down the pipeline as input to another command.

By default, this cmdlet does not generate any output bat by using this OutputMode parameter, the user can select one or more items that will be send down the pipeline.

OutputMode can be set to:

  • None - no items.
  • Single - zero or one item can be selected.
  • Multiple - zero, one or more items can be selected to be send down the pipeline to the next cmdlet.
Example (will try to stop selected processes):

Get-Process | Out-GridView -OutputMode Multiple | Stop-Process