среда, 7 апреля 2021 г.

Delete all computers from WSUS - PowerShell script

# This PowerShell mini-script written by Vladisla2000 is fully ready 

# and should work without any customization to your environment.

cls

$GetWSUS = Get-WsusServer # Get WSUS server as an object

$ComputersObjects = Get-WsusComputer # Gets all computers in WSUS

$ComputersDomainNames = $ComputersObjects.FullDomainName # Extracts Domain names of computers

# Every computer in the loop is deleted

ForEach($Comp in $ComputersDomainNames)

{

Write-Host ""

Write-Host I am deleting "'$Comp'" ... -ForegroundColor Green

($GetWSUS).GetComputerTargetByName("$Comp").Delete() # The main line in the script

Write-Host "'$Comp'" was deleted -ForegroundColor Yellow

}

Write-Host ""

Write-Host FINISHED! -ForegroundColor Green -BackgroundColor Red

понедельник, 22 февраля 2021 г.

PowerShell script to copy groups from one user to another +

There is a useful PowerShell script that is written by friend of mine, talented helpdesk/support person.
He obviously should work in programming field.

I think that the functions of the script are obvious from the picture, 
but the most interesting is by far the possibility to copy groups of one user to another.
It can be useful when creating a new user that should be similar to some existing user.


Here is the script itself.

=START OF SCRIPT=

function form 

    {

    Add-Type -AssemblyName System.Windows.Forms

    Add-Type -AssemblyName System.Drawing

    

     # Build Form

    $form = New-Object System.Windows.Forms.Form

    $form.Text = 'Data Entry Form'

    $form.Size = New-Object System.Drawing.Size(550,300)

    $form.StartPosition = 'CenterScreen'


    #Please enter TZ

    $label = New-Object System.Windows.Forms.Label

    $label.Location = New-Object System.Drawing.Point(10,20)

    $label.Size = New-Object System.Drawing.Size(280,20)

    $label.Text = 'Please enter some value:'

    $form.Controls.Add($label)


    #no coment

    $nf = '

    (\__/)

    (="."=)

    E[:]||||[:]З

    (")_(")'


    #Member of:

    $label2 = New-Object System.Windows.Forms.Label

    $label2.Location = New-Object System.Drawing.Point(340,20)

    $label2.Size = New-Object System.Drawing.Size(280,20)

    $label2.Text = 'Member of:'

    $form.Controls.Add($label2)


    #your username :

    $label2 = New-Object System.Windows.Forms.Label

    $label2.Location = New-Object System.Drawing.Point(10,130)

    $label2.Size = New-Object System.Drawing.Size(280,20)

    $label2.Text = 'uSeRnAmE'

    $form.Controls.Add($label2)


    #search box input

    $inBox = New-Object System.Windows.Forms.TextBox

    $inBox.Location = New-Object System.Drawing.Point(10,40)

    $inBox.Size = New-Object System.Drawing.Size(260,200)

    $form.Controls.Add($inBox)


    #enter user source

    $ussour = New-Object System.Windows.Forms.TextBox

    $ussour.Location = New-Object System.Drawing.Point(320,180)

    $ussour.text="source user"

    $ussour.Size = New-Object System.Drawing.Size(100,10)

    $form.Controls.Add($ussour)


    #enter user target 

    $ustar = New-Object System.Windows.Forms.TextBox

    $ustar.Location = New-Object System.Drawing.Point(320,210)

    $ustar.Text="target user"

    $ustar.Size = New-Object System.Drawing.Size(100,10)

    $form.Controls.Add($ustar)

    

    #box for username output

    $outBox = New-Object System.Windows.Forms.RichTextBox

    $outBox.Location = New-Object System.Drawing.Point(10,155)

    $outbox.font = "arial,10"

    $outBox.Multiline = $true

    $outBox.ScrollBars ="vertical"

    $outBox.Size = New-Object System.Drawing.Size(300,100)

    $outbox.AutoSize = $true

    $form.Controls.Add($outBox)

 

    #box for group 

    $memberofbox = New-Object System.Windows.Forms.TextBox

    $memberofbox.Location = New-Object System.Drawing.Point(320,40)

    $memberofbox.MultiLine = $True

    $memberofbox.ScrollBars = "Vertical"

    $memberofbox.Size = New-Object System.Drawing.Size(200,130)

    $form.Controls.Add($memberofbox)


     # Add search user Button

    $Button = New-Object System.Windows.Forms.Button

    $Button.Location = New-Object System.Drawing.Size(15,75)

    $Button.Size = New-Object System.Drawing.Size(90,23)

    $Button.Text = "search user"

    $Form.Controls.Add($Button)


    # sync groups of users

    $syButton = New-Object System.Windows.Forms.Button

    $syButton.Location = New-Object System.Drawing.Size(440,180)

    $syButton.Size = New-Object System.Drawing.Size(90,53)

    $syButton.Text = "sync groups of users "

    $Form.Controls.Add($syButton)


    # search printer by IP from printer server

    $prButton = New-Object System.Windows.Forms.Button

    $prButton.Location = New-Object System.Drawing.Size(210,75)

    $prButton.Size = New-Object System.Drawing.Size(100,23)

    $prButton.Text = "find printer by IP"

    $Form.Controls.Add($prButton)


    # Add search last log on Button

    $llButton = New-Object System.Windows.Forms.Button

    $llButton.Location = New-Object System.Drawing.Size(115,75)

    $llButton.Size = New-Object System.Drawing.Size(90,53)

    $llButton.Text = "Last logon + -  When Created "

    $Form.Controls.Add($llButton)


    # Add search group Button

    $gButton = New-Object System.Windows.Forms.Button

    $gButton.Location = New-Object System.Drawing.Size(15,105)

    $gButton.Size = New-Object System.Drawing.Size(90,23)

    $gButton.Text = "search group"

    $Form.Controls.Add($gButton)


    #add chekbox

    $chekbox=New-Object System.Windows.Forms.CheckBox

    $chekbox.Location=New-Object System.Drawing.Size(320,20)

    $chekbox.Size=New-Object System.Drawing.Size(15,15)

    $chekbox.Checked = $false

    $form.controls.Add($chekbox)


    #keyboard enter and  esc

    $form.KeyPreview=$True

    #enter

    $form.add_keydown({if ($_.keycode -eq "Enter" ) {$button.PerformClick() } } )


    $form.add_keydown({if ($_.virtualkeycode -eq 38 ) {$gbutton.PerformClick() } } )

    #esc

    $form.add_keydown({if($_.keycode -eq "Escape") {$form.Close() } } )


    $prButton.add_click(

        {

            $ip = $inBox.Text

            $pr=get-WmiObject -class Win32_printer -ComputerName 10.28.28.165,10.28.28.160 | Select-Object -Property  shareName, comment

            foreach($printer in $pr) 

                {

                    if ($printer.comment -eq $ip) 

                        {

                            $outBox.Lines= $printer.shareName

                         }

                }

        }

    )


    #sync group's users 

    $syButton.add_click(

        {

        $usersource = $ussour.Text 

        $usertarget= $ustar.text

        $memof=Get-ADPrincipalGroupMembership $usersource

        $outBox.Forecolor="red"

        $outBox.Lines = "add this groups manauly to user:"

        #set user's group " test123 "

        for ($i=0; $i -le $memof.name.Count-1; $i++)

            {

            #if this NOT Distribution​Group​ and NOT Domain Users

            if ($memof.name[$i] -notmatch "\*" -and $memof.name[$i] -notmatch "Domain Users")

                {

                $q=$memof.name[$i]

                $memberofbox.Appendtext("{0}`n" -f $q)

                Add-ADPrincipalGroupMembership -Identity $usertarget -MemberOf $memof.name[$i]

                }

            else

                {

                $noadd= $memof.name[$i]

                $outBox.Appendtext("{0}`n" -f $noadd)

                }

            }

        }

                        )

    

    #serch last logon date

    $llButton.add_click(

        {

        $x=$inbox.Text

        $x = $x.Trim()

        if($x)             

            {

                $lld = Get-ADUser -LDAPFilter "(sAMAccountName=$x)"

                if($lld)

                    {

                        $out=Get-ADUser -Identity “$x” -Properties “LastLogonDate”,"whenCreated"

                        $outBox.Lines = 'MM/DD/YYYY', $out.LastLogonDate, $out.whenCreated

                    }

                else {$outBox.Lines = "user not found"}

            }

            else {$outBox.Lines = "user not found"}

        }

                        )



    #add group group buton event

    $gButton.add_click(

        {

        $x = $inBox.Text

        if ($x)

            {

                $out=get-adgroup -Filter "name -like '*$x*'" -Properties * | Select-Object name

                $outBox.lines = $out.name

             } 

        else 

            {

                [System.Windows.MessageBox]::Show('Enter something','error')

            }

        }

                        )


    #Add Button event 

    $Button.Add_Click(

        {

        $outbox.Clear()

        $x = $inBox.Text

        if ($x -match '^\d+$')

            {    <#if entering numbers #>

                $out=Get-AdUser -Filter * -Properties postalCode, postOfficeBox, SamAccountName, Enabled | Where-Object {$_.postalCode, $_.postOfficeBox -like $x -or $_.SamAccountName -eq $x }| Select-Object SamAccountName, givenname, surname, Enabled

                chek_out

            }


        elseif ($inBox.TextLength -ne 0) 

            {   <#if entering string #>

                $out = get-ADUser -Filter * -Properties Name, Description, SamAccountName, DisplayName, Enabled, Givenname | where {$_.displayName, $_.Description, $_.FirstName, $_.SamAccountName -like "*$x*"} | Select-Object SamAccountName, Description, Enabled

                chek_out

            }

        else {[System.Windows.MessageBox]::Show('Enter something ','error')}

         }

                    )

     $form.ShowDialog() | Out-Null 

    }

function chek_out

    {

        #if user is  exist then

            if ($out -ne $null )

                {

                    if($out.count -gt 1) #אם נמצא מספר משתמשים 

                        {

                            for ($i=0; $i -le $out.Count-1; $i++)

                                {#הצגת משתמשים לפי כמותם 

                                    if ($out.Enabled[$i] -eq 'true') #user is enable write is green

                                        {$outBox.SelectionColor = 'green'}

                                    else #user is disable write in red

                                         {$outBox.SelectionColor = 'Red'}

                                    $te = $out.SamAccountName[$i] +"    ," + $out.Description[$i] #$te = username + Description

                                    $outBox.Appendtext("{0}`n" -f $te)  #write to outbox

                                }

                         }

                     else #אם נמצא משתמש אחד בלבד

                        { #Description is empty

                            if ($out.Description -eq $null)

                                {

                                    if ($out.Enabled -eq 'true')

                                        {$outBox.Forecolor="green"}

                                    else 

                                        {$outBox.Forecolor="red"}    

                                    $outBox.text= $out.SamAccountName                                    

                                 } 

                             else #Description is NOT empty

                                {

                                    $te = $out.SamAccountName +"     ," + $out.Description

                                    if ($out.Enabled -eq 'true')

                                        {$outBox.Forecolor="green"}

                                    else {$outBox.Forecolor="red"} 

                                    $outBox.Appendtext("{0}`n" -f $te)

                                 }

                             if ($chekbox.Checked -eq $true) 

                                  {

                                   #get member of and put them to memberofbox like text 

                                   $memof=Get-ADPrincipalGroupMembership $out.SamAccountName | select name 

                                   $memberofbox.Text = $memof.name | Out-String

                                   }

                        }

                 }

                #if user not found

            else 

                {

                    [System.Windows.MessageBox]::Show("Not found")

                    #$outBox.Text = "Not found"

                    $memberofbox.text = $nf 

                }        

    }

function Hide-Console

{

    Add-Type -Name Window -Namespace Console -MemberDefinition '

[DllImport("Kernel32.dll")]

public static extern IntPtr GetConsoleWindow();


[DllImport("user32.dll")]

public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);

'

    $consolePtr = [Console.Window]::GetConsoleWindow()

    #0 hide

    [Console.Window]::ShowWindow($consolePtr, 0)

}

Hide-Console

form

#nltest /DSGETDC:domain.local

==END OF SCRIPT==

пятница, 22 января 2021 г.

Find Remote Logon Computer IP with Event Viewer or PowerShell

At times, it is necessary to find the IP address of a computer that logs onto a Domain Controller or another server. This may be required, for instance, if a user is getting constantly locked out after changing their password, and they cannot recall which computer is being used to access a service or application on their behalf.

Many IT administrators are unaware of where to find this crucial piece of information. A Google search may not yield a specific result that is easy to locate, so I'm here to share some tips with you.

Open Event Viewer,
Go to Applications and Services Logs - Microsoft - Windows - TerminalServices-RemoteConnectionManager - Operational



 

 

 

 





If you click on it, you will easily see this IP information.


 

 

 

 

 



Using PowerShell, it is possible to find both the user who is currently logged in and the IP address of their computer:

===START===

#=Find Currently Logged On User + IP=#

$CurrentUsers = quser
$CurrentUsers = $CurrentUsers[1..$CurrentUsers.Length] | % {$_.trim().Split(" ")[0].Replace(">", "")}

$Events = Get-WinEvent -FilterHashtable @{
    Logname   = 'Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational'
    ID        = 1149
    StartTime = (Get-Date).AddDays(-31)    
}
$EventObjects = @()
$Events | % {
    $EventXML = [xml]$_.ToXml()
    $obj = New-Object -TypeName PSObject -Property @{
        Username  = $EventXML.Event.UserData.EventXML.Param1
        IP        = $EventXML.Event.UserData.EventXML.Param3
        Timestamp = [datetime]$EventXML.Event.System.TimeCreated.SystemTime
    }
    $EventObjects += $obj
}

$CurrentSessions = $CurrentUsers | ForEach-Object {
    $EventObjects | Sort-Object -Property Timestamp -Descending | Where-Object Username -eq $_ | Select-Object -First 1
}

$CurrentSessions | Select-Object Username, IP, Timestamp
====END====

 

суббота, 16 января 2021 г.

VMWare Snapshot with PowerShell

 Get-VM VLAD2020 | New-Snapshot -Name "DEMO" -Description "Created $(Get-Date)" -Quiesce -Memory –RunAsync


It took me about a minute. For about a 40 seconds the VM was freezed, but this is the most comprehensive way of snapshotting that gives reliable results in restoring VMs.


среда, 13 января 2021 г.

Slow working computer

If your computer is running slow, here are some steps to follow:

  1. Check for and clean temporary files.
  2. Check your RAM and add more if necessary.
  3. Check your CPU and add more if necessary.
  4. Update VMware Tools.
  5. Upgrade VM Compatibility.
  6. Check for any pending Windows updates and install them.
  7. Scan your computer for spyware and viruses.
  8. Remove any unnecessary add-ins in your applications.
  9. Check for any outdated programs.
  10. Restart your computer (the most obvious and often effective step for Windows computers).
  11. Check the size and number of files on your desktop, as many large files can slow down your computer.
  12. Ensure that there is enough free space on your hard drive.
  13. Check if your firmware is updated.

These steps will help you identify and fix some of the common reasons for slow computer performance.

Here are the explained steps to follow:

  1. Check the temporary folder by entering %TEMP% in the search bar, Run dialog box, or Command Prompt.
  2. Delete files in C:\Windows\temp
  3. Delete files in C:\Windows\Logs\CBS If you're unable to delete the CBS.log file, stop the TrustedInstaller service, delete CBS.log, and then start the service again. Alternatively, you can end the task with the same name.
  4. If these steps are not sufficient, you can use the free CleanUp program available at this link: http://stevengould.org/downloads/cleanup/CleanUp40.exe
  5. Adding more RAM and CPU is much easier to do on a virtual machine. To diagnose the issue, open the Task Manager, go to the Performance tab, and run the problematic application or file to see what happens.
  6. Updating VMware Tools and upgrading VM Compatibility are necessary for VMWare virtual machines only.
  7. Check for pending Windows updates that may be waiting to install and restart your computer.
  8. Spyware and viruses can often cause slow performance, so run a virus scan to check for any infections.
  9. Outdated programs may not be fully compatible with newer computers and may need to be updated.
  10. Cleaning temporary files and restarting the computer can often help.
  11. Having too many files on the desktop can slow down the computer, so consider moving them to another location.
  12. Low disk space can cause severe performance issues, so ensure that there is enough free space on your hard drive.
  13. Updating firmware may also help improve performance, especially on new computers.

These are the most common causes of slow-running computers. For more advanced issues, advanced tools like those from the Sysinternals site (author Mark Russinovich) may be needed. Additionally, slow network or defective hardware can also cause slow performance, but we will not be discussing these external cases in this article.



воскресенье, 10 января 2021 г.

Export printers with IP - PowerShell

Sometimes we need to know IP of all printers on a print server, but default Printers view doesn't have it.
Even if you try to add fields in the View - Add/Remove Columns... it is not there.

So we have no choice not to use our old friend PowerShell.

-=-=-=-=START-=-=-=-=-=-=-=-
$printserver = "Printserver-Name" 

Get-WMIObject -class Win32_Printer -computer $printserver  Select Name,DriverName,PortName  Export-CSV -path 'C:\All-Printers.csv'

-=-=-=-=END-=-=-=-=-=-=-=-

How to оpen PDF in Adobe Reader instead in IE

Sometimes PDF files are been opened in Internet Explorer while we want them open in Adobe Reader. 

1. Make Adobe Reader default.

2. Disable IE integration.

3. IE - General - "Open pop-ups in a new windows".

4. Add a site to local trusted sites.

I managed to work at Metropolinet, while I got this knowledge (thanks to Kseniya).



четверг, 7 января 2021 г.

Export PST from Exchange2010 - PowerShell

 cls

<# PST Export from Exchange2010 with PowerShell #
Use on Exchange2010 or workstation with Exchange2010 tools installed #>

Set-ExecutionPolicy Bypass -force

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://Exchange2010.Domain.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential

Import-PSSession $Session

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

# Add-ADGroupMember Administrators -Members "Exchange Trusted Subsystem"

# New-RoleGroup -Name “Exchange Mailbox Import Export” -Roles “Mailbox Import Export” -Members "Domain\Administrators" -Display Name”Exchange Mailbox Import Export”

$Mailbox = ""

$PSTname = ""

$DirPath = ""

$JoinedPath = ""

$Mailbox = "User@milgam.co.il"

$PSTname = "$Mailbox.pst"

$DirPath = "\\X.X.X.X\$Mailbox\"

$FilePath = Join-Path $DirPath -ChildPath $PSTname

# New-Item -ItemType Directory -Path $DirPath # (= MD $PSTPath)

ii $DirPath

New-MailboxExportRequest -Mailbox $Mailbox -FilePath $FilePath

# Get-MailboxExportRequest -status Completed | Remove-MailboxExportRequest # for clearing purposes

<#

If you get error "New-MailboxExportRequest : Unable to open PST file" you can give the
COMPUTER that you run this script from write permissions on the share/folder $DirPath.
Also it may be lack of permissions for "Exchange Trusted Subsystem".
#>


воскресенье, 3 января 2021 г.

Windows System Commands 1.7 (extended ver.)

 

Page 1

System Info

Whoami returns the user’s login name

Hostname returns the computer name

Msconfig GUI for configuring boot, services, startup…

Msinfo32 GUI for info, including remote computers

Systeminfo CLI tool for info
Net config workstation CLI for host/user/domain/OS info…

=Last restart/power on date=

net statistics workstation # For CMD

net stats work | find "Stat" # For CMD

net stats work | select-string "Stat" # PoSH

Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime

systeminfo | Select-String "System Boot Time" # PoSH

systeminfo | find "Boot Time" # CMD

Sysdm.cpl System properties (old way)

Win+Pause System window (new way)

Echo %username% logged on %computername% at %date%
Echo %username%
logged on %computername >> \\server\share\file
Remote commands

Mstsc /v:Server /admin (/console)

Psexec \\Server CMD - CLI remote connection
Change logon /Enable – execute after Psexec
Change logon /Query – execute after Psexec

Processes, Services, Sessions
=Services=
Sc queryex servicename finds PID of an installed service
Sc config servicename start= disabled - change service startup type
Sc config servicename start= auto - change service startup type

=Processes=

Taskkill /pid PID /F – kills a process by PID
Taskkill /t /IM processname /F
– kills a process with its children (/t)
Tasklist /svc /fo list | more
shows all processes on a computer

Tasklist | findstr processname  finds PID of a started process

Taskkill /FI "memusage gt 102400" /F – kills RAM processes <100mb

=Sessions=

Query session /SERVER:server – queries sessions for PID
Quser /SERVER:server queries sessions + info of a user’s logon time
Reset session PID /SERVER:server – kills session by PID
Rwinsta PID /SERVER:server – kills session by PID
Logoff PID /SERVER:server – kills session by PID
For /F "Tokens=*" %a in (Servers.txt) Do Logoff – kills the number
of sessions with a text file

NTFS Permissions
takeown /f D:\test /A /R /D Y
– grants ownership to the Admins group (/A) recursively (/R) with Yes answer (/D Y). Can use UNC path.
iCacls D:\test /setowner "Administrators" /T /C – grants ownership
iCacls D:\test /grant Administrators:(OI)(CI)M /F /T /C – Modify prm
iCacls D:\test /remove "Administrators" /T /C – removes user recurs.
‘Previous commands’ | find /I “denied” >> C:\err.log – makes log file

Windows Update troubleshooting
Wuauclt /resetauthorization /detectnow /updatenow
Net stop wuauserv => del C:\Windows\SoftwareDistribution => start
Netsh winhttp reset proxy
WSReset.exe
– clears & resets Windows Store cache on Win8.1/10

Network
=Basic commands=
Firewall local state
- netsh advfirewall show allprofiles
Firewall remote state (PoSH) - Invoke-Command -ComputerName [ComputerName] -ScriptBlock {netsh advfirewall show allprofiles}
Allow WMI (PoSH)- netsh firewall set service RemoteAdmin enable
Tracert hostname traces path by given IP
Pathping hostname traces path by given IP + localhost + statistics

=Checking MAC address=
Getmac
shows MAC address of a local computer
Getmac /s server MAC address of a remote computer
Ping Server (then) Arp -a MAC address of a remote computer
=DNS commands=

Nslookup computer – DNS info about some host (external command)
> server 4.4.8.8
– changes DNS server to be used (internal command)
Nslookup –q=MX <host> <DNS server> – changes default record type
Dnscmd server /statistics > D:\filename – DNS info
Telnet install 
Telnet install Cmd - Pkgmgr /iu:"TelnetClient"
PowerShell - Install-WindowsFeature -name Telnet-Client
DISM /online /Enable-Feature /FeatureName:TelnetClient

Netstat commands

Netstat shows open TCP ports in the form of server:port
Netstat -a
adds UDP ports
Netstat -o
shows PID (not in Win2000)
Netstat -b displays involved EXE files
Netstat -ao shows TCP/UDP ports and PIDs 
Netstat –n 5 shows output every 5 seconds
Netstat –a | find "135" shows process that listens on port 135 
Netstat –a | find "established" shows established process
(possible parameters: listening/established/time_wait/close_wait) 
Netstat –ao | find “192.168” – shows processes with PID

Netsh commands
Netsh winsock reset
resets IP stack
Netsh int ip reset anyfile.txt resets IP stack
Netsh advf set allp state off – disable FW with CMD
Netsh interface tcp show global – general TCP info
Netsh –r interface ip show interfaces local info about net interfaces
Netsh –r server interface ip show interfaces remote interfaces info

=Solving network speed problems=

Netsh interface tcp show global
(Look for "Receive Window Auto-Tuning Level". You should see normal.)

Netsh interface tcp set global autotuning=disabled
Netsh interface tcp set global autotuning=normal
Netsh interface tcp set global rss=disabled
Netsh interface tcp set global rss=enabled

Active Directory
Repadmin /showrepl – shows AD replication
Repadmin /syncall Server.dom.com
– activates AD replication
Ldp.exe
– GUI view on Active Directory
Set logonserver
– DC authenticated the *User*
Echo %logonserver% – DC authenticated the *User*

Nltest /query /SERVER:server – queries netlogon service status
Nltest /SERVER:server /finduser:username – user Domain & DC Nltest /DCLIST:Domain – list of DCs in Domain

Nltest /DSGETDC:Domain  DC authenticated the *Computer*

Exchange Server (Powershell)
=Show all organizational databases=

Get-MailboxDatabase –STATUS
Get-MailboxDatabase –STATUS | format-table name,mounted,backupinprogress,onlinemaintenanceprogress

Get-MailboxDatabase – STATUS | select servername,name,databasesize
Get-MailboxDatabase – STATUS | select servername,name,databasesize | Sort-Object Name -Descending
Get-MailboxDatabase – STATUS | select servername,name,databasesize | Sort-Object DatabaseSize –Descending

=Show databases on the particular Exchange Server=

Get-MailboxDatabase –SERVER servername
Get-MailboxDatabase –SERVER servername –Status | format-table name,mounted,backupinprogress
Get-MailboxDatabaseCopyStatus –SERVER  servername

=Check status of the particular database=
Get-MailboxDatabase dbname

=Check the date of Exchange Last Full Backup=

Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ft name,latestfull*
Get-MailboxDatabase –SERVER server  -status | fl name, *fullbackup

=Product key=
Entering a product key (GUI) - Slui
Entering a product key (CMD) - slmgr -ipk XXXXX-XXXXX
Check activating status - slmgr /xpr
Check license status - slmgr /dli

=How to add Windows Backup feature=
Import-Module ServerManager ; Add-WindowsFeature Backup

Additional commands

=Enable Remoting=
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
=Enable LUA UAC from CMD (reboot)=

reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f

=Add computer to domain (PoSH)=
Add-Computer -DomainName DOM.Local -Credential DOM\Admin -restart -force

=Check CMD status =
sc.exe query lanmanworkstation (should only show MRxSmb20)

=Enable SMBv1 with CMD=

dism /online /enable-feature /featurename:SMB1Protocol-Server

=ENABLE SMB1 with PoSH=

Enable-WindowsOptionalFeature -Online -FeatureName "SMB1Protocol-Client" -All

=Disable SMBv1 CMD=

sc.exe config lanmanworkstation depend= bowser/mrxsmb20/nsi
sc.exe config mrxsmb10 start= disabled

=Uninstall app with CMD=
wmic product get description | findstr /C:"Unlocker"
wmic product where "description='Unlocker' " uninstall

or enter to wmic
wmic
product get name
product where name="Unlocker" call uninstall (needs exact name)

=Syncing computer time with DC=

w32tm /config /syncfromflags:domhier /update
Then run:
net stop w32time
net start w32time


=Delete files by date=

forfiles –p C:\Share\ -s –m *.* -d -1 –c “CMD /C del /Q /F /s @path”