Monday, August 22, 2011

Some addendum on modules

If you add modules like  PSUserTools from Microsoft you receive some enhanced functionality. You also receive some well conceived script.  After you have imported your modules ('import-module'), you can use a function like that below to list all the exported commands:

function Global:get-module_exports {

$commands=(get-module $ModName).ExportedCommands
[Array[]]$list=(($commands).Values) | %{$_.Name} | Sort

PS C:\> get-module -list
ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   PSUserTools               {}
PS C:\> import-module PSUserTools
PS C:\> get-module_exports PSUserTools

'Get-CurrentUser' queries WMI to find domain and local users. Here is a simplified function derived from that script that prints out local users and their SIDs:

function net_user
function netusers {$query = "Win32_UserAccount";$query+= " WHERE LocalAccount='True'";Get-WmiObject $query }
netusers | % {($" "+($_.SID)}

PS C:\ net_user  [SIDs deleted for privacy]
Administrator S-1-*
Guest S-1-*
rferrisx S-1-*

No comments: