#create-DHCPScopes
$fileData = Get-Content c:\temp\scripts\some-file.txt
$fileData | %{
# header of my file - tab is separator
# SHORT_SUBNET SUBNET_MASK DHCP-LO DHCP-HI GW NAME
$line = $_
$tabline = $line.Split("`t")
$name = $tabLine[5]
$dhcpName = """$name"""
$description = "some descritpion"
if ($tabline[0] -ne "SHORT_SUBNET") {
netsh dhcp server add scope $tabLine[0] $tabline[1] $dhcpName $description
netsh dhcp server scope $tabLine[0] set state 1
netsh dhcp server scope $tabLine[0] set name $dhcpName
netsh dhcp server scope $tabLine[0] set optionvalue 003 IPADDRESS $tabLine[4]
netsh dhcp server scope $tabLine[0] set optionvalue 051 DWORD 2592000
netsh dhcp server scope $tabLine[0] add iprange $tabLine[2] $tabLine[3]
}
}
Pokazywanie postów oznaczonych etykietą script. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą script. Pokaż wszystkie posty
2018-08-09
netsh dhcp create scope
How to create dhcp scopes in older system - without dhcp module:
2018-07-16
measure ldap bind time - for Active Directory powershell script
How to check simple bind anonymously for all domain controllers? Maybe using this script:
Output is formatted with tabs co You can copy/paste strictly to Excel or to Word and convert to a table.
#####################Variables#####################
$repeats = 10
###################################################
#####################Main#####################
import-module activedirectory
cls
$myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$domCtrls = $myforest.Sites | % { $_.Servers } | Select Name
$domCtrls | %{
$domCtrl = $_
$totalTime = 0
$i = 0
$maxTime = 0; $minTime = 100
while ($i -ne $repeats) {
$c = New-Object System.DirectoryServices.Protocols.LdapConnection ($domCtrl.Name + ":389")
# Anonymous, Basic, Digest, DPA (Distributed Password Authentication),
# External, Kerberos, Msn, Negotiate, Ntlm, Sicily
$c.AuthType = [System.DirectoryServices.Protocols.AuthType]::Anonymous
$c.SessionOptions.ProtocolVersion = 3
$c.SessionOptions.SecureSocketLayer = $false
$time = (Measure-Command {$c.Bind()}).TotalSeconds
$c.Dispose()
$totalTime += $time
if ($minTime -gt $time) { $minTime = $time }
if ($maxTime -lt $time) { $maxTime = $time }
$i++
}
$avgTime = $totalTime / $repeats
$domCtrl.name + "`t" + $minTime + "`t" + $avgTime + "`t" + $maxTime
}
Output is formatted with tabs co You can copy/paste strictly to Excel or to Word and convert to a table.
check group policy templates - compare-ADMX.ps1
How to find missing admx or adml files - of course - You should provide proper path and regional settings:
import-module ActiveDirectory
cls
$currentDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$currentDomain = $currentDomain.Name
$admls = get-item ("c:\windows\sysvol_dfsr\sysvol\" + $currentDomain + "\Policies\PolicyDefinitions\en-us\*.adml")
$admxs = get-item ("c:\windows\sysvol_dfsr\sysvol\" + $currentDomain + "\Policies\PolicyDefinitions\*.admx")
$admls | %{
$adml = $_
$admlName = $adml.name
$admlFullName = $adml.FullName
$admxName = $admlName.Substring(0, $admlName.Length - 5) + ".admx"
if (Get-Item ($admlFullName + "\..\..\" + $admxName) -ErrorAction SilentlyContinue) {
#do nothing
} else {
".......... " + $admxName + " is missing"
}
}
$admxs | %{
$admx = $_
$admxName = $admx.name
$admxFullName = $admx.FullName
$admlName = $admxName.Substring(0, $admxName.Length - 5) + ".adml"
if (Get-Item ($admxFullName + "\..\en-us\" + $admlName) -ErrorAction SilentlyContinue) {
#do nothing
} else {
".......... " + $admlName + " is missing"
}
}
2018-04-03
TMG DNS cache - draft
Dim root
Set root = CreateObject("FPC.Root")
'Declare the other objects that are necessary.
Dim array ' An FPCArray object
Dim settings ' An FPCLowLevelSettings
' Get references to the array object and to the low-level
' settings object.
Set array = root.GetContainingArray
Set settings = array.ArrayPolicy.LowLevelSettings
WScript.Echo "DNS cache settings:" & vbCrLf & _
" TTL of entries for unsuccessful lookups: " & _
settings.DnsCacheNegativeTtl & vbCrLf & _
" Maximum size of a single record: " & _
settings.DnsCacheRecordMaxKB & vbCrLf & _
" Maximum size of the Firewall service DNS cache: " & _
settings.DnsCacheSize
The following VBScript code sets a new value for the DnsCacheNegativeTtl property: ' Create the root object.
Dim root
Set root = CreateObject("FPC.Root")
'Declare the other objects that are necessary.
Dim Policy ' An FPCArrayPolicy object
' Get an array policy object and set the new value of the
' DnsCacheNegativeTtl property of the low-level
' settings object.
Set Policy = root.GetContainingArray.ArrayPolicy
Policy.LowLevelSettings.DnsCacheNegativeTtl = 7200
Policy.Save
WScript.Echo "Done!"
2018-03-29
undelete/recover Active Directory object - powershell
Restore-ADObject -identity (Get-ADObject -SearchBase (get-addomain).DeletedObjectsContainer -IncludeDeletedObjects -filter "sAMAccountName -eq 'OneOfDeletedNames'").distinguishedNameof course OneOfDeletedNames should has dollar sign ($) at the end when deleted object is a computer account.
or for multiple objects
("comp1", "user1345", "jOhnSmith12") | %{ Restore-ADObject -identity (Get-ADObject -SearchBase (get-addomain).DeletedObjectsContainer -IncludeDeletedObjects -filter "sAMAccountName -eq '$_'").distinguishedName}
Subskrybuj:
Posty (Atom)