วันพุธที่ 19 มิถุนายน พ.ศ. 2562

Remote edit Group policy another computer


Remote edit Group policy another computer


Start --> run --> gpedit.msc /gpcomputer: IP_Target

Powershell: Close Auto Update Local Group Policy


Powershell: Close Auto Update Local Group Policy


##Install Module for Support Policy##
Install-Module -Name PolicyFileEditor



$RegPath = 'Software\Policies\Microsoft\Windows\WindowsUpdate\AU'

$RegName = 'NoAutoUpdate'
$RegData = '1'
$RegType = 'DWord'


Set-PolicyFileEntry -Path \\IP_Target\C$\Windows\System32\GroupPolicy\Machine\Registry.pol -Key $RegPath -ValueName $RegName -Data $RegData -Type $RegType

##Show Policy on Target##
Get-PolicyFileEntry -Path \\IP_Target\c$\Windows\System32\GroupPolicy\Machine\Registry.pol -all

Error: Sysprep


Error: Sysprep



ตามภาพ เมื่อ Sysprep แล้ว รอ Process พบว่าเกิด Error ขึ้น

สามารถทำการแก้ไข ได้ดังนี้ครับ

1. Shift+F10 (เพื่อเปิด Command Prompt มาใช้งาน)
2. cd oobe
3. msoobe
4. wait repair process
5. reboot & finish

วันพฤหัสบดีที่ 13 มิถุนายน พ.ศ. 2562

Automate Configuration Switch Cisco from Powershell Scripts


Automate Get-Configuration Cisco from Powershell Scripts


###---------------------------------------###
### Author : Yingkamol Prukrattanakul-----###
###---MCP, MCSA, MCSE, MCT, MCST, SEC+----###
###---Email<yingkamol_7@hotmail.com>------###
## Blogger: https://yingkamol.blogspot.com ##
###---------------------------------------###
###//////////////..........\\\\\\\\\\\\\\\###
###/////////////////.....\\\\\\\\\\\\\\\\\###

##powershell for management SW##

param(
    [int] $port = 23,
        [string] $command1 = "terminal length 0",
        [string] $command2 = "en",
        [string] $command4 = "show run",
    [int] $commandDelay = 1000
   )
[string] $output = ""

function GetOutput
{
  ## Create a buffer to receive the response
  $buffer = new-object System.Byte[] 1024
  $encoding = new-object System.Text.AsciiEncoding

  $outputBuffer = ""
  $foundMore = $false

  ## Read all the data available from the stream, writing it to the
  ## output buffer when done.
  do
  {
    ## Allow data to buffer for a bit
    start-sleep -m 1000

    ## Read what data is available
    $foundmore = $false
    $stream.ReadTimeout = 1000

    do
    {
      try
      {
        $read = $stream.Read($buffer, 0, 1024)

        if($read -gt 0)
        {
          $foundmore = $true
          $outputBuffer += ($encoding.GetString($buffer, 0, $read))
        }
      } catch { $foundMore = $false; $read = 0 }
    } while($read -gt 0)
  } while($foundmore)

  $outputBuffer
}


##HQ##
$remoteHost = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip.txt
$username = Get-Content D:\Ying\PowerShell\mgmt_sw\user.txt
$password = Get-Content D:\Ying\PowerShell\mgmt_sw\password.txt
$password1 = Get-Content D:\Ying\PowerShell\mgmt_sw\password-en.txt

##Pak1##
$remoteHost1 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip1.txt

##Pak2##
$remoteHost2 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip2.txt

##Pak3##
$remoteHost3 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip3.txt

##Pak4##
$remoteHost4 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip4.txt

##Pak5##
$remoteHost5 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip5.txt

##Pak6##
$remoteHost6 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip6.txt

##Pak7##
$remoteHost7 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip7.txt

##Pak8##
$remoteHost8 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip8.txt

##Pak9##
$remoteHost9 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip9.txt

##Pak10##
$remoteHost10 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip10.txt

##Pak11##
$remoteHost11 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip11.txt

##Pak12##
$remoteHost12 = Get-Content D:\Ying\PowerShell\mgmt_sw\sw-ip12.txt


function HQ
{
            ForEach ($remoteHosts in $remoteHost)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\HQ-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\HQFailedlogin.txt"
                    }
            }
}

function PAK1
{
            ForEach ($remoteHosts in $remoteHost1)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK1-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK1Failedlogin.txt"
                    }
            }
}

function PAK2
{
            ForEach ($remoteHosts in $remoteHost2)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK2-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK2Failedlogin.txt"
                    }
            }
}

function PAK3
{
            ForEach ($remoteHosts in $remoteHost3)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK3-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK3Failedlogin.txt"
                    }
            }
}

function PAK4
{
            ForEach ($remoteHosts in $remoteHost4)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK4-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK4Failedlogin.txt"
                    }
            }
}

function PAK5
{
            ForEach ($remoteHosts in $remoteHost5)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK1-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK5Failedlogin.txt"
                    }
            }
}

function PAK6
{
            ForEach ($remoteHosts in $remoteHost6)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK6-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK6Failedlogin.txt"
                    }
            }
}

function PAK7
{
            ForEach ($remoteHosts in $remoteHost7)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK7-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK7Failedlogin.txt"
                    }
            }
}

function PAK8
{
            ForEach ($remoteHosts in $remoteHost8)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK8-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK8Failedlogin.txt"
                    }
            }
}

function PAK9
{
            ForEach ($remoteHosts in $remoteHost9)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK9-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK9Failedlogin.txt"
                    }
            }
}

function PAK10
{
            ForEach ($remoteHosts in $remoteHost10)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK10-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK10Failedlogin.txt"
                    }
            }
}

function PAK11
{
            ForEach ($remoteHosts in $remoteHost11)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK11-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK11Failedlogin.txt"
                    }
            }
}

function PAK12
{
            ForEach ($remoteHosts in $remoteHost12)
            {
                try
                {
                write-host "Connecting to $remoteHosts on port $port"     
                trap { Write-Error "Could not connect to remote computer: $_"; exit }
                $socket = new-object System.Net.Sockets.TcpClient($remoteHosts, $port)
                write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
                $stream = $socket.GetStream()
                $writer = new-object System.IO.StreamWriter $stream
                    ## Receive the output that has buffered so far
                            $writer.WriteLine($username)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command2)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($password1)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                            $writer.WriteLine($command4)
                        $writer.Flush()
                        Start-Sleep -m $commandDelay
                        $SCRIPT:output += GetOutput
                ## Close the streams
                $writer.Close()
                $stream.Close()
                $output |Out-File "D:\Ying\PowerShell\mgmt_sw\PAK12-$remoteHosts.txt"
                }
                catch
                    {
                    $Failedlogin = "System FailedUser:$remoteHosts"
    echo $Failedlogin > "D:\Ying\PowerShell\mgmt_sw\PAK12Failedlogin.txt"
                    }
            }
}

วันพฤหัสบดีที่ 6 มิถุนายน พ.ศ. 2562

Microsoft Office 365: Change Password From Condition


Microsoft Office 365: Change Password From Condition


##Install Module for Manage Resource in AzureAD##

Install-Module -Name AzureAD -Force

##User Credential##

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential


Connect-MsolService


##Get All Users in Domain##
##Show 
UserPrincipalName, DisplayName, WhenCreated##
##WhenCreated = 6/24/2018##
#
#Force Change Password##

Get-Msoluser -All | Select-Object UserPrincipalName, DisplayName, WhenCreated | FT -AutoSize

Get-Msoluser -All | Where-Object WhenCreated -ge 6/24/2018 | Set-MsolUserPassword -NewPassword 'Contoso$@!678' -ForceChangePassword:$TRUE


Microsoft Office 365: Add License All Domain


Microsoft Office 365: Add License All Domain


##Install Module for Manage Resource in AzureAD##

Install-Module -Name AzureAD -Force

##User Credential##

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential


Connect-MsolService


##Get All Users in Domain##
##Add License##


Get-msoluser -DomainName "test.contoso.co.th" | Set-MsolUserLicense  -AddLicenses contoso:STANDARDWOFFPACK_STUDENT

Microsoft Office 365: Set New Password All Domain


Microsoft Office 365: Set New Password All Domain


##Install Module for Manage Resource in AzureAD##

Install-Module -Name AzureAD -Force

##User Credential##

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential


Connect-MsolService


##Get All Users in Domain##
##Force Set Password##

Get-msoluser -all -DomainName "test.contoso.co.th" | Set-MsolUserPassword -NewPassword 'Contoso$@!345' -ForceChangePassword:$TRUE