My new blog
Blog is moved to new domain, please update you shortcuts ❤
Knowledge Base – http://www.blog.klyavlin.ru
List Active Directory group members
Get-ADGroupMember "group_name"
But this cmdlet contains poor amount of properties to use. And if you need load more information about listed users you can pipeline results to another cmdlet with lots of properties: Get-ADUser.
Below is example of group members list sorted by Display Name. You can select any property similar way.
Import-Module ActiveDirectory
# There is an inputbox for group name #
$gr_name=Read-Host "Input AD group name:"
# Results of Get-ADGroupMember pipelined to Get-ADUser as input #
# Display Name property selected and sort-order is set. #
Get-ADGroupMember $gr_name | Get-ADUser -properties displayname | select DisplayName | Sort-Object -Property displayname
Write-Host "-----------"
- Script language: PowerShell
- Read permissions to AD required
Restart WiFi adapter if it hangs
I use this script on my laptop half a year already. It triggers every minute and works fine.
- Script language: VBScript
- Changing Network Adapter setting requires administrative privileges.
Script Block
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colWiFi=objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapter")
ArrRemoteHosts = Array("ya.ru","8.8.8.8","google.com")
FailCount = 0
First of all we connect to local WMI and selecting all network adapters. Then creating array of remote hosts ( ArrRemoteHosts ). We will ping them to determine Wi-Fi connection state. There are several hosts to be sure that the problem not in remote host, but in Wi-Fi connection. FailCount var is used to store remote host state.
FOR EACH WiFi in colWiFi
IF InStr(1, WiFi.name, "wireless", 1) > 0 THEN
IF WiFi.NetEnabled = "True" THEN
Now we gonna parse list of selected adapters to find the one, which name contains “wireless“. That is what we need, but need to check is it enabled or not. Because you could disable it yourself and scheduled script will enable it back – not cool.
FOR EACH RemoteHost in ArrRemoteHosts
Set colPing=objWMIService.ExecQuery ("SELECT * FROM Win32_PingStatus WHERE Address = '" & RemoteHost & "'")
FOR EACH ping in colPing
IF ping.StatusCode = 0 and ping.ResponseTime < 300 THEN
WScript.Quit
ELSE
FailCount = FailCount + 1
END IF
NEXT
NEXT
Once we found right network adapter we start to checking remote hosts accessibility. IF StatusCode = 0 there is no error during ICMP exchange. But I found that sometimes wifi freezes not completely and ping actually pathing through but ResponceTime incredible high. So its equals offline state of wifi. If both parameters are fine while pinging first host in array – script quits, but if its not – FailCount increase. Quit after first successfully pinged remote host makes script “lighter” especially if its scheduled, for example, once per minute.
IF FailCount = 3 THEN
WiFi.Disable()
WScript.Sleep 3000
WiFi.Enable()
END IF
END IF
END IF
NEXT
On the last step we check FailCount and if all three remote host output an error or pings too high – network adapter state is changing to disabled and then back to enabled. Sleep is used for timeout while state is changing.
nslookup
- nslookup syntax:
- nslookup –type=”record type” “ip/name to resolve” “dns server to ask for“
- if parameter is empty next defaults is used:
- –type default A-record
- dns server to ask for default Network Connection DNS settings
- Query examples:
nslookup ya.ru 8.8.8.8 // default A-record query
nslookup -type=ptr 8.8.4.4 8.8.8.8 // PTR-record query
nslookup -type=mx google.com 8.8.8.8 // MX-record query
Send e-mail from freeBSD
/usr/bin/mail -s “Subject” user@domain.com <<< “Body”
