piątek, 24 sierpnia 2018

LDAP error codes

LDAP: error code 49 - 80090308: LdapErr: DSID-0C090400, comment: AcceptSecurityContext error, data 52e, v1db1 ​
525​ user not found ​
52e​ invalid credentials ​​
530​ not permitted to logon at this time​​
531​ not permitted to logon at this workstation​​
532​ password expired ​​
533​ account disabled ​​
701​ account expired ​​
773​ user must reset password ​​
775​ user account locked​

niedziela, 12 sierpnia 2018

windows 10 - enable hibernation

From elevated command prompt just type:
powercfg /hibernate on
If you receive this error:
Unable to perform operation.  An unexpected error (0x65b) has occurred:  Function failed during execution.
it just means that You haven't got local administrator's permission - You must just run cmd as administrator.

Active Directory - create root domain

This can be done through PowerShell script - as below:
Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012R2" `
-DomainName "contoso.com" `
-DomainNetbiosName "CONTOSO" `
-ForestMode "Win2012R2" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true
or using GUI:

create NAT switch for hyper-v

Get adapters to find current list of adapters before any changes - just to notice changes.

PS C:\WINDOWS\system32> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet                  Intel(R) 82579LM Gigabit Network Con...      20 Disconnected F0-DE-F1-8A-12-5C          0 bps
Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...      19 Disconnected 94-39-E5-8F-C1-79         3 Mbps
WiFi                      Intel(R) Centrino(R) Ultimate-N 6300...      13 Up           24-77-03-19-4A-08       144 Mbps
vEthernet (Default Swi... Hyper-V Virtual Ethernet Adapter              8 Up           1A-15-25-D5-36-C5        10 Gbps

Create new VMSwitch - name is custom - You should use something noticable - with NAT phrase, but it is of course optional, switch type is important - You can choose from Internal, External and Private - choose Internal.

PS C:\WINDOWS\system32> New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal

Name      SwitchType NetAdapterInterfaceDescription
----      ---------- ------------------------------
NATSwitch Internal


PS C:\WINDOWS\system32> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet                  Intel(R) 82579LM Gigabit Network Con...      20 Disconnected F0-DE-F1-8A-12-5C          0 bps
Bluetooth Network Conn... Bluetooth Device (Personal Area Netw...      19 Disconnected 94-39-E5-8F-C1-79         3 Mbps
vEthernet (NATSwitch)     Hyper-V Virtual Ethernet Adapter #2          50 Up           00-15-5D-04-20-06        10 Gbps
WiFi                      Intel(R) Centrino(R) Ultimate-N 6300...      13 Up           24-77-03-19-4A-08       144 Mbps
vEthernet (Default Swi... Hyper-V Virtual Ethernet Adapter              8 Up           1A-15-25-D5-36-C5        10 Gbps

New adapter connected to the new switch has interface index (ifIndex) 50 - we will assign other components to this interface. Let's create IP address - it will be default gateway for our NAT network.

PS C:\WINDOWS\system32> New-NetIPAddress -IPAddress 192.168.254.254 -PrefixLength 24 -InterfaceIndex 50


IPAddress         : 192.168.254.254
InterfaceIndex    : 50
InterfaceAlias    : vEthernet (NATSwitch)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Tentative
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 192.168.254.254
InterfaceIndex    : 50
InterfaceAlias    : vEthernet (NATSwitch)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore

So we have switch, we have ip address connected with interface in this switch and now - we must inform system - that we have network behind NAT. We can have only ONE network behind NAT, so let's inform system about it.

PS C:\WINDOWS\system32> New-NetNat -Name NATnetwork -InternalIPInterfaceAddressPrefix 192.168.254.0/24


Name                             : NATnetwork
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 192.168.254.0/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True


Now we can reconnect our virtual machines to the new switch and reconfigure them:
- network addresses from 192.168.254.0/24 network;
- default gateway 192.168.254.254;
- DNS server - depends on configuration, for example 8.8.8.8.
Our NAT network:

PS C:\WINDOWS\system32> Get-NetNat


Name                             : NATnetwork
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 192.168.254.0/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True

Our NAT Switch:

PS C:\WINDOWS\system32> Get-VMSwitch

Name           SwitchType NetAdapterInterfaceDescription
----           ---------- ------------------------------
Default Switch Internal   Teamed-Interface
NATSwitch      Internal

czwartek, 9 sierpnia 2018

netsh dhcp create scope

How to create dhcp scopes in older system - without dhcp module:
#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]
    }
}