PowerShell Hosts Info, Servers, Computers One-Liners
Hosts Info, Servers, Computers, etc...
Get BIOS Version
· Get-WMIObject Win32_BIOS -computername servername
Get Manufacturer and Model
· Get-WmiObject -Class Win32_computersystem -ComputerName |select model, manufacturer
See Registered SnapIns
· get-pssnapin -registered
read in a file and perform some action on it
· get-content ulist.txt | foreach-object {get-qaduser $_}
Get Windows Architecture
· function Get-Architecture {
param($computer)
(Get-WmiObject -computername $computer -class Win32_OperatingSystem ).Caption
}
· PS C:\Windows> env computerName
Get all commands for a snappin
· get-Command -PSSnapin VMware.VimAutomation.Core | more
Find version of PS, vSphereCLI,etc
· get-host, Get-PowerCLIVersion
Get Serial Number
· $snum = (get-wmiobject win32_bios -computername $env:computername).SerialNumber.toString()
Get Disk Size Information
· get-WmiObject Win32_logicaldisk -computer srv0fs02 | Format-Table DeviceId, MediaType, Size, FreeSpace -auto
Get DN Information
· Get-QADObject 'Mysite' -Type OrganizationalUnit
· Get-QADObject 'Mysite' -Type OrganizationalUnit
Get Domain and Subnets from forest.
· [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | select Name, subnets
# And For More detail
· [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | select name, @{n='subnets';e={$_.subnets | select -expand name}}, @{n='servers';e={$_.Servers | select -expand name}}, @{n='sitelink';e={$_.sitelinks | select -expand name}}
Connect to Different Domain
· $pw = read-host "Enter password" -AsSecureString C:\PS>connect-QADService -service
· 'server.company.com' -ConnectionAccount 'company\administrator' -ConnectionPassword $pw
Get list of Physical servers in AD
· get-qadcomputer -sizelimit 0 -osname '*Server*' | where {$_.dn -match "mysite"} | where {$_.dn -match 'servers'} | where {$_.description -notmatch 'VM'}
Get List of Servers in OU and List Name & Operating System
· get-qadcomputer -sizelimit 0 -osname '*Server*' | where {$_.dn -match "mysite"} |
· where {$_.dn -match 'servers'} | select name, operatingsystem | out-gridview
Get List of print server printer information to include IP addresses
· get-wmiobject -class win32_printer -computername MyPrintServer | where {$_.sharename -ne $null}|select systemname,sharename, portname | out-gridview
Get List of Network Card Configurations
· Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName computerName | format-list *
Search for all NICS from server list with description containing word 'team'
· get-content mg2list.txt | foreach-object {
$nicCheck = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ |where {$_.description -like "*team*"}
$nicCheck |format-table Description >> teams.txt
}
View, Change or Stop Service
· Set-Service $service -startuptype manual
· set-service flexlmautodesk -startuptype manual -computername fdxflexlm1
· get-service $service
· stop-service $service
Account Management
list primary smtp address
· $addy = (get-mailbox twalters).PrimarySMTPAddress.toString() ; write-host $addy
unlock user account
· unlock-qaduser -identity username
change user password
· Set-QADUser -userPassword "Lapt00p$" -userMustChangePassword 1 -identity loser
Add Full Access to Exchange
· add-mailboxpermission -identity someuser -user exchadmins -accessrights fullaccess
Extend Account 90 Days
· set-qaduser 'username' -accountexpires (Get-Date).addDays(90)
Expire Account
· set-qaduser 'username' -AccountExpires (get-date).AddDays(-1)
Get All Enabled Accounts
· get-qaduser -enabled | where { $_.DN -match "mysite"} | select-object name
Check if User has 'H' Drive
· (get-qaduser twalters).homedirectory
Get Direct Reports for manager/supervisor
· Get-QADUser -LdapFilter "(manager:1.2.840.113556.1.4.1941:=CN=user name (Mysite),OU=Users,OU=Standard Users,OU=Users and computers,ou=mysite,dc=company,dc=com)"
get-qaduser -manager mgrname | select name
Get User's Manager or List all Direct Reports for Manager
· (get-qaduser "Todd Walters").manager
· get-qaduser -manager "Managers Name" |format-table name, samaccountname
Get User Last Logon Time
· (Get-QADUser username).lastLogon
Enable Computer Account - Move from disabled OU and Enable account
· Move-QADObject SRV0W26JFAY -NewParentContainer "Mysite.com/SITE/Mysite/Users And Computers/Standard Users/Computers" | foreach {enable-qadcomputer $_.name}
Get List of All Users On LOA (and in Disable OU)
· get-qaduser -sizeLimit 0 -description '*LOA*' | where {$_.dn -match "mysite" } | select name, description
· get-qaduser -sizeLimit 0 -description '*LOA*' | where {$_.dn -match "mysite" } | where-object {$_.ParentContainer -like "*Disabled*"}
Check if Communicator is Enabled or See Communicator properties
· Get-QADUser twalters -IncludeAllProperties | fl msRTCSIP-UserEnabled
· Get-QADUser twalters -IncludeAllProperties | fl msRTCSIP*
To return only single item. Useful for creating list
· PS H:\MyScripts> get-qaduser twalters | foreach-object {$_.lastname}
note: .lastname can be any property, useful for getting just name, not CN of something.
No comments:
Post a Comment