Monday, August 5, 2013

PowerShell Shares and Filesystems One-Liners


Shares, Filesystems, etc...

·         get shares  
·         get-WmiObject -class Win32_Share -computer srv0fs02 | sort type,  name


·         Get share Acess
·         (get-acl \\server\share).access
·         Get-acl  share | format-list

get users home  drive
·         $drive = get-wmiobject win32_share -computername srv0fs02 |  where-object {$_.path -like "*twalters"}
echo  $drive.path
E:\Home1\TWalters
Alt Method:   get-WmiObject Win32_Share -computer srv0fs02 -filter "Name  ='twalters$'"

Unshare a share  (does not delete)
·         $unshare = get-wmiobject win32_share -computer  srv0fs02 | where {$_.Name -eq "loser$"}
·         $unshare.delete()
Alt-Method    
·         (get-wmiobject win32_share -computer $hserve -Filter  "name='username$'").InvokeMethod("Delete",$null )

Get home server  
·         $hdrive = (get-qaduser  joeking).homedirectory.toString()
·         $homeserver = $hdrive.substring(2,9)
·         PS  C:\scripts> write-host $homeserver
·         srv0fs02

No comments:

Post a Comment