Windows/powershell
Aus SchnallIchNet
Snippets for powershell
Note that Exchange-related powershell commands should be listed here
Inhaltsverzeichnis
external AD-snapin
http://software.dell.com/products/active-roles/powershell.aspx
Nach der Installation dann mit folgendem command einbinden:
Add-PSSnapin Quest.ActiveRoles.ADManagement
Und damit kannst du dann tolle Sachen machen wie:
Get-QADGroup -ContainsMember username
get loadable modules
Get-Module -ListAvailable
get primary DC (PDC)
Netdom Query Fsmo
Get Service names
Get-Service | Where-Object {$_.displayName.StartsWith("watch")} | Select name
get list of services that start with watch* (case sensitive)
Get-Service | Where-Object {$_.displayName.StartsWith("watch")} | Start-Service Get-Service | Where-Object {$_.displayName.StartsWith("watch")} | Stop-Service Get-Service | Where-Object {$_.displayName.StartsWith("watch")} | Restart-Service
Get Group Memberships of AD-Object
Get-ADPrincipalGroupMembership -identity <USER>
Search/Filter Users
Get-ADUser -Filter * -Properties DisplayName, EmailAddress, Title -SearchBase 'OU=Fleetservices User,DC=fleetservices,DC=intra' \ -Server 'Fleetservices.intra'
or export result to CSV-File
Get-ADUser -Filter * -Properties DisplayName, EmailAddress, Title -SearchBase 'OU=HPI,DC=fleet,DC=int' \ -Server 'Fleet.int' | Export-CSV c:\temp\FleetInt.csv
Search/Filter Computers
Get-ADComputer -SearchBase 'OU=Build,OU=MemberServers,dc=europe,dc=arifleet,dc=com' -Filter '*'
robocopy
robocopy F:\SOURCE D:\DESTINATION\ /MIR /FFT /Z /W:5 /tee /log:RobocopySync.log
- /MIR specifies that robocopy should mirror the source directory and the destination directory. Beware that this may delete files at the destination.
- /FFT uses fat file timing instead of NTFS. This means the granularity is a bit less precise.
- /W:5 reduces the wait time between failures to 5 seconds instead of the 30 second default.
- /Z ensures robocopy can resume the transfer of a large file in mid-file instead of restarting.
- /XA:H makes robocopy ignore hidden files, usually these will be system files that we’re not interested in.
- /log:RobocopySync.log write output into logfile instead stdout. Use in combination with /tee to get output to stdout AND logfile
- /COPY:copyflag[s] what to COPY for files (default is /COPY:DAT). (copyflags : D=Data, A=Attributes, T=Timestamps). (S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
set thumbnail-image
from an exchange server
Import-RecipientDataProperty -Identity dSchlenzig -Picture -FileData \ ([Byte[]]$(Get-Content -path ".\thumb-DOMARI.jpg" -Encoding Byte -ReadCount 0))
from an AD
$photo = [byte[]](Get-Content path of pic -Encoding byte) Set-ADUser username -Replace @{thumbnailPhoto=$photo}