The author of a Github Powershell script I'm often using for scanning media files for errors has uploaded a new file to the same repo called "Commands_JD.ps1" and this is it's content:


# Eventlog
Get-WinEvent -ListLog * -EA silentlycontinue |
where-object { $_.recordcount -AND $_.lastwritetime -gt [datetime]::today} |
foreach-object { get-winevent -LogName $_.logname -MaxEvents 1 } |
Format-Table TimeCreated, ID, ProviderName, Message -AutoSize –Wrap

# Arguments
function FktWriteToLog {
        write-host $($args[0])
        }
        FktWriteToLog "Some text"
Getting more details of last error
$Error[0] | Format-List -Force

#PsExec Alternative in PowerShell (Invoke-PsExec)
#For true PsExec-like functionality, there’s an open-source PowerShell module called Invoke-PsExec, which uses PsExec under the hood and communicates over port 445.

#To install the module and use it:
Install-Module -Name Invoke-PsExec -Scope CurrentUser
Invoke-PsExec -ComputerName "RemoteComputerName" -Credential (Get-Credential) -Command "notepad.exe"
#This approach closely mirrors PsExec's functionality and connects over port 445.







# Find a string in multiple files
Get-ChildItem \\10.9.42.2\c$\Scripts\Packages -Recurse | Select-String "houic-s-8068" -List | Select Path

# User profile
Get-CimInstance -Class Win32_UserProfile -ComputerName muntse-s-81043 | Where-Object { $_.LocalPath.split('\')[-1] -eq 'J.Devasahayam-A' } | Remove-CimInstance
Get-Wmiobject -Class Win32_UserProfile -ComputerName plkrwdotdir01 | Where-Object { $_.LocalPath.split('\')[-1] -eq 'J.Devasahayam-A' } | Remove-wmiobject -WhatIf


# Get file details:
Get-ChildItem $somepath | Select-Object @{n = 'LastWriteTime'; e = { $_.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") } }, Length, Name
Get-ChildItem $somepath |
Select-Object @{n = 'LastWriteTime'; e = { $_.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") } },
Length,
Name
Get-Childitem -path  $somepath | Select-Object Name, @{Name = "KBytes"; Expression = { "{0:N0}" -f ($_.Length / 1KB) } }
#
Get-ChildItem -path "E:\DATA\ELogRepository\Managed-Servers" -Recurse | Where-Object { $_.LastWriteTime -le (Get-Date).AddDays(-91) } |
select-object Name, FullName,
@{n = 'CreationTime'; e = { $_.CreationTime.ToString("yyyy-MM-dd--HH-mm-ss") } },
@{n = 'LastWriteTime'; e = { $_.LastWriteTime.ToString("yyyy-MM-dd--HH-mm-ss") } },
@{Name = "KBytes"; Expression = { "{0:N0}" -f ($_.Length / 1KB) } },
Attributes | export-csv c:\temp\ELogRepository91le.csv -NoTypeInformation
#
Get-ChildItem "E:\DATA\ELogRepository\Managed-Servers" -Recurse | Where-Object { $_.LastWriteTime -le (Get-Date).AddDays(-91) } | select-object FullName, @{n = 'CreationTime'; e = { $_.CreationTime.ToString("yyyy-MM-dd--HH-mm-ss") } }, @{n = 'LastWriteTime'; e = { $_.LastWriteTime.ToString("yyyy-MM-dd--HH-mm-ss") } }, @{Name = "KBytes"; Expression = { "{0:N0}" -f ($_.Length / 1KB) } }, PSIsContainer, Attributes | export-csv c:\temp\ELogRepository91le.csv -NoTypeInformation
#
#Install CAB files
Add-WindowsPackage -Online -PackagePath "C:\Temp\Windows10.0-KB4586853-x64.cab"
dism /online /add-package /packagepath:"C:\Temp\Windows10.0-KB4586853-x64.cab" 


$Details = "" | Select-Object ServerName, PingStatus, WMIStatus, NLAStatus

# Get NLA status
Get-WmiObject -class Win32_TSGeneralSetting -Namespace root\cimv2\terminalservices | Select-Object UserAuthenticationRequired
$WMIParams = @{

        Class       = 'Win32_TSGeneralSetting'
    
        Namespace   = 'root\CIMV2\TerminalServices'
    
        Filter      = "TerminalName='RDP-Tcp'"
    
        ErrorAction = 'Stop'
    
}
    
Get-WmiObject @WMIParams
#
# File version:
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("somefilepath").FileVersion
get-childitem * -include *.dll, *.exe | foreach-object { "{0}`t{1}" -f $_.Name, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).FileVersion }

#TLS versions to use:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
or
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#Get SecurityProtocol:
[Net.ServicePointManager]::SecurityProtocol

Invoke-WebRequest "https://microsoft.com"
Eventlogs:
Get-EventLog -LogName security -Message *Security ID:* | where-object { $_.eventid -eq 4670 } | Select-Object -Property EntryType, TimeGenerated, Source, EventID, Category, Message
Get-EventLog -LogName Application | Select-Object -Property EntryType, TimeGenerated, Source, EventID, Category, Message

Windows activation status (KMS)
# https://learn.microsoft.com/en-us/previous-versions/windows/desktop/sppwmi/softwarelicensingproduct?redirectedfrom=MSDN
Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select Description, LicenseStatus, KeyManagementServiceMachine
Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | Select-Object `
        DiscoveredKeyManagementServiceMachineIpAddress,
DiscoveredKeyManagementServiceMachineName,
DiscoveredKeyManagementServiceMachinePort,
LicenseStatus,
PartialProductKey,
ProductKeyChannel,
TrustedTime,
IsKeyManagementServiceMachine
#
Get-EventLog -LogName Application | Select-Object -Property EntryType, TimeGenerated, Source, EventID, Category, Message

Get-EventLog -LogName "Key Management Service" | select -newest 5

#netstat with process names
Get-NetTCPConnection | select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State , OwningProcess  , @{l = "Name" ; e = { Get-Process -Id $_.OwningProcess | select -ExpandProperty Name } } | Format-Table

#get-process with username
Invoke-Command -ComputerName amsdc1-s-42732 -ScriptBlock { Get-Process -IncludeUserName | Where-Object username -like *-a* | sort username } | Export-Csv users.csv -NoTypeInformation

# Robocopy scripts:
robocopy 1MB file max
/MAX:1048576
\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\FCI\V1.1
\\amsdc1-s-8686\tsdp$\Wintel\Scripts\Handover\Handover_2022
\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\DCPL\V2.1
"V:\Users\a11339050\OneDrive - Deutsche Telekom AG\01_JD_Data\Scripts_jd\T\PostInstallation\DCPL\V2.1"
robocopy "\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\DCPL\V2.1" "V:\Users\a11339050\OneDrive - Deutsche Telekom AG\01_JD_Data\Scripts_jd\T\PostInstallation\DCPL\V2.1" /S /E /r:0 /MAX:1048576
Dest:
V:\Users\a11339050\OneDrive - Deutsche Telekom AG\01_JD_Data\JD_Scripts

robocopy "\\amsdc1-s-8686\tsdp$\Wintel\Scripts\Handover\Handover_2022" "V:\Users\a11339050\OneDrive - Deutsche Telekom AG\01_JD_Data\JD_Scripts\TSYS\Handover_2022" /S /E /r:0 /MAX:1048576


robocopy "\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\V2.0" "V:\Users\a11339050\OneDrive - Deutsche Telekom AG\01_JD_Data\Scripts_jd\T\PostInstallation\V2.0" /S /E /r:0 /MAX:1048576

\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\DCPL
\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\FCI
\\amsdc1-s-8686\tsdp$\Wintel\Scripts\PostInstallation\V2.0

#

# C:\Users\a11339050\OneDrive - Deutsche Telekom AG\01_JD_Data\Scripts_jd\T
# Internet Explorer version
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer
# Value

#Windows update
get-wmiobject -class win32_quickfixengineering | sort-object installedon | select -last 1
#
C:\Server\Tools\WSUS\psexec.exe wuauclt /detectnow
#Windows update history:
get-wmiobject -class win32_quickfixengineering
get-wmiobject win32_quickfixengineering | sort installedon -desc
# JD To check wsus installation status : 
Get-Content C:\Windows\SoftwareDistribution\ReportingEvents.log -Tail 1 -Wait
#
Get-Content "c:\windows\WindowsUpdate.log" | Select-Object -Last 5   # for older PS versions
#
get-eventlog system | where-object { $_.eventid -eq 6005 } | select -first 10 | ft -auto
get-itemproperty -path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Detect"
get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results"
get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"

# Windows 2019 : 
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
WUServer
WUStatusServer
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
AUOptions

wuauclt.exe /detectnow
get-service wuauserv | Restart-Service
#
dir HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
Name                           Property
----                           --------
AU                             AutoInstallMinorUpdates       : 1
NoAUShutdownOption            : 1
UseWUServer                   : 1
DetectionFrequencyEnabled     : 1
DetectionFrequency            : 22
NoAutoUpdate                  : 0
AUOptions                     : 4
ScheduledInstallDay           : 1
ScheduledInstallTime          : 3
ScheduledInstallEveryWeek     : 1
NoAUAsDefaultShutdownOption   : 1
NoAutoRebootWithLoggedOnUsers : 1
RescheduleWaitTimeEnabled     : 0
#
PS C:\> Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\
AutoInstallMinorUpdates       : 1
NoAUShutdownOption            : 1
UseWUServer                   : 1
DetectionFrequencyEnabled     : 1
DetectionFrequency            : 22
NoAutoUpdate                  : 0
AUOptions                     : 4
ScheduledInstallDay           : 1
ScheduledInstallTime          : 3
ScheduledInstallEveryWeek     : 1
NoAUAsDefaultShutdownOption   : 1
NoAutoRebootWithLoggedOnUsers : 1
RescheduleWaitTimeEnabled     : 0
PSPath                        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Wind
ows\WindowsUpdate\AU\
PSParentPath                  : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Wind
ows\WindowsUpdate
PSChildName                   : AU
PSDrive                       : HKLM
PSProvider                    : Microsoft.PowerShell.Core\Registry
#
PS C:\> Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate

WUServer                           : http://az-eu-mvc0003.recodom02.com:8530
WUStatusServer                     : http://az-eu-mvc0003.recodom02.com:8530
UpdateServiceUrlAlternate          :
SetProxyBehaviorForUpdateDetection : 0
ElevateNonAdmins                   : 0
TargetGroupEnabled                 : 1
TargetGroup                        : Europe
PSPath                             : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
PSParentPath                       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows
PSChildName                        : WindowsUpdate
PSDrive                            : HKLM
PSProvider                         : Microsoft.PowerShell.Core\Registry
#
#Create a CIM session to multiple computers
New-CimSession -ComputerName Server01, Server02, Server03
#Create a CIM session with a friendly name
New-CimSession -ComputerName Server01, Server02 -Name FileServers
Get-CimSession -Name File*
#Create a CIM session using DCOM
$SessionOption = New-CimSessionOption -Protocol DCOM
New-CimSession -ComputerName Server1 -SessionOption $SessionOption
# Update Windows Defender definitions
Update-MpSignature

#netstat alternative:
Get-NetTCPConnection | select Local*, Remote*, State, `
@{n = "ProcessName"; e = { (Get-Process -Id $_.OwningProcess).ProcessName } }, `
@{n = "ProcessPath"; e = { (Get-Process -Id $_.OwningProcess).Path } } | ft -Auto
#Linux commands:
du -sk * | sort -n 
du -sh * | sort -h
#check port in Linux : nc -zv <remote IP> <remote port>

#Join to domain:
Add-Computer -ComputerName w2k22-Test`
-Credential recodom02.com\Administrator `
        -LocalCredential Server01\Admin01 `
        -DomainName recodom02.com `
        -OuPath 'OU=MVS,OU=Servers,DC=recodom02,DC=com' `
        -Restart -Force -PassThru
#recodom02.com/Servers/MVS/az-eu-mvc0002
Add-Computer -DomainName recodom02.com -OUPath "OU=MVS,OU=Servers,DC=recodom02,DC=com"
Add-Computer -DomainName recodom02.com -OUPath "OU=MVS,OU=Servers,DC=recodom02,DC=com" -Credential recodom02\osadmin -Restart -Force -PassThru -Verbose
Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force -PassThru -Verbose
Add-Computer -DomainName europe.shell.com -OUPath "OU=FCI,OU=Servers,OU=HNS,DC=europe,DC=shell,DC=com" -PassThru -Verbose
# europe.shell.com/HNS/Servers/FCI
europe.shell.com/Server Directory/Application Servers/Application Development/AMSD2A-S-95127
Add-Computer -DomainName europe.shell.com -OUPath "OU='Application Development',OU='Application Servers',OU='Server Directory',DC=europe,DC=shell,DC=com" -PassThru -Verbose
#This workd:
Add-Computer -DomainName europe.shell.com -OUPath "OU=Application Development,OU=Application Servers,OU=ServerDirectory,DC=europe,DC=shell,DC=com" -PassThru -Verbose
#Proc UtilizationDistinguishedName : CN=AMSD2A-S-95111,OU=Application Development,OU=Application Servers,OU=ServerDirectory,DC=europe,DC=shell,DC=com
Add-Computer -DomainName europe.shell.com -Verbose -PassThru -Credential $cred
(Get-WmiObject -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average
#Memory Utilization
$ComputerMemory = Get-WmiObject -Class win32_operatingsystem -ErrorAction Stop
$Memory = ((($ComputerMemory.TotalVisibleMemorySize - $ComputerMemory.FreePhysicalMemory) * 100) / $ComputerMemory.TotalVisibleMemorySize) 
$RoundMemory = [math]::Round($Memory, 0)
$RoundMemory
# Network capture
#Elevated command prompt
netsh trace start capture=yes IPv4.Address=X.X.X.X
netsh trace start persistent=yes capture=yes IPv4.Address=X.X.X.X tracefile=c:\temp\nettrace-boot.etl

netsh trace stop
#Get registry value recursively
Get-ChildItem -path HKLM:\SOFTWARE\ -Recurse | where { $_.Name -match 'java' -or $_.Name -match 'jre' }

# Get process "command line"
$process = "notepad.exe"
Get-CimInstance Win32_Process -Filter "name = '$process'" | select CommandLine
Get-CimInstance Win32_Process | select CommandLine
Get-CimInstance Win32_Process | select CommandLine | select-string java*
# Get the processes from specific path:
Get-CimInstance -ClassName 'Win32_Process' | Where-Object { $_.ExecutablePath -like 'e:\apps\j*' } | Select-Object @{n = 'Name'; e = { $_.Name.Split('.')[0] } }
# Get Instlaled Programs
Get-WmiObject Win32_Product | 
Sort InstallDate | 
Select Name, Caption, Version, Vendor, InstallDate
# Method 2:
Get-CimInstance -Filter 'NAME LIKE "%1C%"' -ClassName 'Win32_Product' | 
Select -ExpandProperty 'Version'

Get-WmiObject -Class Win32_Product -ComputerName $ComputerName -Filter "Name like 'Java%'" | Foreach-Object { $_.Version }
Get-WmiObject -Class Win32_Product -Filter "Name like 'Java%'" | Foreach-Object { "$_.Version" }
#Uptime
Get-CimInstance -ClassName Win32_OperatingSystem | Select LastBootUpTime
#Commenting in PS script
<#
Any text here
#>

#To find out the version and build number of your Windows. Use the following PowerShell command:
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer, OsArchitectur
#

#Delete a file recursively
Get-ChildItem -Path "C:\Temp" -Include desktop.ini -File -Recurse | foreach { $_.Delete() }
Get-ChildItem -Path "D:\01_JDLifeData\01_JD_Family\IncomeTax_ITR" -Include desktop.ini -File -Recurse | foreach { $_.Delete() }
Get-ChildItem -Path "D:\" -Include desktop.ini -File -Recurse -hidden | foreach { $_.Delete() }
D:\01_JDLifeData\01_JD_Family\IncomeTax_ITR
#GPUpdate remotely:
Invoke-GPUpdate -Computer “computername” -RandomDelayInMinutes 0

Invoke-GPUpdate -Computer “AMSDC3-MVC0006” -RandomDelayInMinutes 0
#2
$computers = Get-ADComputer -Filter *
$computers | ForEach-Object -Process { Invoke-GPUpdate -Computer $_.name -RandomDelayInMinutes 0 -Force }


#Lastboottime
Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime

# Windows firewall 2019
Get-NetFirewallProfile │select name, enabled
Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled false  # To disable firewall
Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled true # To enable firewall
# firewall.cpl

#VS Code formatting : Shift + Alt + F
#Create new file
New-Item -Path 'c:\monitoring\HP\conf\tsi_oa_activate.conf' -ItemType file -force

get-eventlog system -EntryType error -Newest 5 | Select-Object TimeGenerated, EntryType, Source, EventID, UserName, MachineName, Message | ft -AutoSize

# vpnagent

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\vpnagent
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run


#Example 7: Get all computers with a name starting with a string AND password last set before 30 days
$Date = [DateTime]::Today.AddDays(-30)
Get-ADComputer -Filter 'Name -like "Computer01*" -and PasswordLastSet -ge $Date' -Properties IPv4Address | FT Name, DNSHostName, IPv4Address -A
name        dnshostname            ipv4address
----        ---------- - ---------- -
Computer01-SRV1 Computer01-SRV1.Computer01.com 10.194.99.181


#Example 5: Get all computer accounts using a filter
Get-ADComputer -Filter *



#CanonicalName

Get-ADComputer -Filter * -Properties IPv4Address | FT Name, DNSHostName, IPv4Address, CanonicalName -A
#Export all AD Computers to CSV file
Get-ADComputer -Filter * -Properties * |
Select -Property Name, DNSHostName, IPv4Address, CanonicalName, Enabled, LastLogonDate | 
Export-CSV "C:\AllComputers.csv" -NoTypeInformation -Encoding UTF8

#Windows product key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform , find value of BackupProductKeyDefault


 
Invoke-Command { (cscript /Nologo "C:\Windows\System32\slmgr.vbs" /xpr) -join '' } -ComputerName xy

#Not working in Shell: Invoke-Command { (cscript /Nologo "C:\Windows\System32\slmgr.vbs" /xpr) -join '' } -ComputerName houcy1-s-6251

Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | 
Where-Object { $_.PartialProductKey } | Select-Object Description, LicenseStatus

#Remote computers
Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ComputerName RemoteComp | 
Where-Object { $_.PartialProductKey } | Select-Object Description, LicenseStatus


Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ComputerName muntse-s-70054 | Where-Object { $_.PartialProductKey } | Select-Object Description, LicenseStatus
$licensing = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ComputerName muntse-s-70054 | Where-Object { $_.PartialProductKey } 
ProductKeyChannel
PartialProductKey
LicenseStatus
KeyManagementServiceMachine
ProductKeyID
ProductKeyID2

MUNTSE-S-81040
MUNTSD-S-70975

Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" -ComputerName MUNTSE-S-81040 | Where-Object { $_.PartialProductKey } | Select-Object Description, LicenseStatus

slmgr-vbs /dlv -computername MUNTSE-S-81040

(Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002 -Name Functions).Functions
HKLM\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002!Functions


Invoke-Command -ComputerName Member01, Server01 { Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS1.0\Client' -Name Enabled | Select-Object Enabled }


Invoke-Command -ComputerName AZ-EU-MVC0001 { Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS1.0\Client' -Name Enabled | Select-Object Enabled }



Get-EventLog -LogName security | Where-Object { $_.InstanceID -like '514*' }

# Disable services
get-service -ComputerName $ip | Where-Object { $_.Name -eq 'SNMPTRAP' } | Set-Service -StartupType  Disabled


get-service -ComputerName AZ-EU-MVC0001, AZ-EU-MVC0002, AZ-EU-MVC0003 | Where-Object { $_.Name -eq 'SNMPTRAP' } | Set-Service -StartupType  Disabled


get-help about_comparision_operators -showwindow
get-hlep *comparison*
#Get-Eventlog properties
get-eventlog system -Newest 5 
TimeGenerated, EntryType, Source, EventID, Message, UserName, MachineName

#Error system events newest 5
get-eventlog system -EntryType error -Newest 5 | Select-Object TimeGenerated, EntryType, Source, EventID, UserName, MachineName, Message | ft -AutoSize
#All system events newest 5
get-eventlog system -Newest 5 | Select-Object TimeGenerated, EntryType, Source, EventID, UserName, MachineName, Message | ft -AutoSize

#Get installed hotfixes
Get-Hotfix | Select-Object –Property HotFixID, Description, InstalledOn, InstalledBy | sort-object -property InstalledON -Descending
Get-Hotfix | Select-Object –Property HotFixID, Description, @{n = 'HotFixAge'; e = { (New-TimeSpan -Start $PSItem.InstalledOn).Days } }, InstalledBy | sort-object -property HotFixAge




#Command to add MSL group to local admin
powershell -command "& { ([adsi]'WinNT://./administrators,group').Add('WinNT://shell/fSys-HNS-SCv2-MigrationServiceLine-GS,group'); }"
powershell -command "& { ([adsi]'WinNT://./administrators,group').Add('WinNT://shell/APS-GRNP-SCV2-DCBS_TST_OS_SUPPORT_TEAM-LS,group'); }"

#Europe\FGO-SI-HAG-ZZ-AD-R1-SBX-GS
powershell -command "& { ([adsi]'WinNT://./administrators,group').Add('WinNT://FGO-SI-HAG-ZZ-AD-R1-SBX-GS,group'); }"

#fSys-HNS-SCv2-SQLOperationsRNM
#rCmp-HNSSCv2SQLAT2
powershell -command "& { ([adsi]'WinNT://./administrators,group').Add('WinNT://shell/fSys-HNS-SCv2-SQLOperationsRNM,group'); }"
powershell -command "& { ([adsi]'WinNT://./administrators,group').Add('WinNT://shell/rCmp-HNSSCv2SQLAT2,group'); }"

#To start PowerCLI:
. 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'


powershell -command "& { ([adsi]'WinNT://./administrators,group').Add('WinNT://APP-SITI-RIJKES-ZZ-IRM-IP-PROJ-LS,group'); }"

# To Get Robocopy version
gcm robocopy | fl *

#Robocopy Switch for maximum fil size
# /MAX:n :: MAXimum file size - exclude files bigger than n bytes. 
# /MAX:1024 # max 1 KB
# /MAX:1048576 # max 1 MB

ping 203.115.201.98
ping 203.115.201.99
test-connection 203.115.201.98
test-connection 203.115.201.99

clear-host
Get-Item HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters | ForEach-Object { Get-ItemProperty $_.pspath }
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters | ForEach-Object { Get-ItemProperty $_.pspath }
write-host 1
write-host 2
sc.exe qc lanmanworkstation

invoke-command -ComputerName PEJJBT-S-08166 -ScriptBlock { & 'C:\Program Files\HP\HP BTO Software\bin\win64\ovconfget.exe' > c:\temp\ovconfget.txt }

#KMS config
#slmgr.vbs /skms 156.31.192.126 1688
#slmgr.vbs /skms dcpwav22179985:1688
(GET-ADUSER â€“Identity 'ASIA-PAC\Udit.Sinha' â€“Properties MemberOf | Select-Object MemberOf).MemberOf


Get-Eventlog -LogName Security | where { $_.EventId -eq "4624" } | select-object @{Name = "User"; Expression = { $_.ReplacementStrings[5] } } | sort-object User -unique
Get-EventLog System -Source Microsoft-Windows-Winlogon -ComputerName $computer | select $UserProperty, $TypeProperty, $TimeProperty


#Services - Non C:\ drive
Get-WmiObject Win32_Service | Where-object { $_.pathname -notlike "*c:*" } | select-object Name, DisplayName, State, StartMode | ft -autosize
# Dir \\amsdc1-s-70000\x2vmigration -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select LastWriteTime, Name, Directory -last 10 | sort LastWriteTime â€“Descending | ft -autosize


E:\DATA\X2VMigration
# Dir E:\DATA\X2VMigration -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select LastWriteTime, Name, Directory -last 10 | sort LastWriteTime â€“Descending | ft -autosize

bginfo.exe c:\users\lowell\bin\config.bgi /timer:0 /nolicprompt /silent
#Powercli
#Get-NetworkAdapter -vm "dcplnx23009181_dcpesx23009181" |select Name, MacAddress, NetworkName, ConnectionState | ft -autosize
Get-NetworkAdapter -vm "dcpwin23110088" | select Name, MacAddress, NetworkName, ConnectionState | ft -autosize
#C:\01-JD_Data\JD-Scripts_BigSize\MSLX2V_2.8.8_WIP
Dir "C:\01-JD_Data\JD-Scripts_BigSize\MSLX2V_2.8.8_WIP" -r | ? { ! $_.PSIsContainer } | sort LastWriteTime | select LastWriteTime, Name, Directory -last 10 | sort LastWriteTime â€“Descending | ft -autosize
#X:\DATA\X2VMigration\MSLX2V
Dir "X:\DATA\X2VMigration\MSLX2V" -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize

Dir "e:\DATA\X2VMigration\MSLX2V" -r | ? { ! $_.PSIsContainer } | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize

powershell.exe -Command "& { restart-service ntrtscan; }"
powershell.exe -Command "& { restart-service tmlisten; }"
Dir "C:\Program Files (x86)\Trend Micro\OfficeScan Client\*.log" -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize
Dir "C:\Program Files (x86)\Trend Micro\OfficeScan Client" -r | ? { ! $_.PSIsContainer } | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize
Dir "C:\Program Files\HP\HP BTO Software" -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize
Dir "C:\ProgramData\HP\HP BTO Software" -r | ? { ! $_.PSIsContainer } | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize
C:\ProgramData\HP\HP BTO Software
Dir "C:\ProgramData\HP\HP BTO Software\" -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize
Dir "D:\FTP\" -r | ? { ! $_.PSIsContainer } | sort LastWriteTime | select LastWriteTime, FullName -last 20 | sort LastWriteTime â€“Descending | ft -autosize
Get-WmiObject win32_networkadapterconfiguration | select description, macaddress
#esxcli commands
esxcli system maintenanceMode set --enable true # To enter into maintenance mode
esxcli system maintenanceMode set --enable false
esxcli system maintenanceMode get

Net user jdevasah /ACTIVE:YES

\\10.102.156.201\e$\Data\MSL_FrieslandCampina\Tools\uptime.exe
Enter-PSSession -ComputerName IANNLACTX11


Get-WmiObject -List | Where { $_.name -match 'User'}
Get-WmiObject win32_service -computername SRPAPP301120
Get-WmiObject win32_service -credential SS64\Simon -computer Server64

#PowerCLI $jd2 = Get-View -ViewType VirtualMachine -Filter @{'Name'='AA3HC095'}

#Open VMConsole: 
Get-VM VMName | Open-VMConsoleWindow
Get-VM â€œWin2k3â€ | Open-VMConsoleWindow #Example
Set-PowerCLIConfiguration â€“VMConsoleWindowBrowser â€œC:\Program Files\Internet Explorer\iexplore.exeâ€ #To set the browser
Set-PowerCLIConfiguration â€“VMConsoleWindowBrowser â€œ$nullâ€ #To clear above setting

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares #Shares
Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True'" | select name, fullname

#To get subdirectories count:
Write-Host ( Get-ChildItem 'E:\PlanningOne\PlanningOne_Acceptance\UP\UP Unconventionals (UPU)' -Recurse -Directory | Measure-Object ).Count;
Get-ChildItem 'E:\PlanningOne\PlanningOne_Acceptance\UP\UP Unconventionals (UPU)' -Recurse -Directory | Measure-Object | %{$_.Count}


#Get disks size output to text file
Get-Wmiobject -query “select name, SystemName, driveletter, capacity, freespace from win32_volume where drivetype=3" | Format-Table -autosize SystemName,Name, @{ label=”SizeGB”; Expression={($_.capacity / 1GB).tostring(“F0")}}, @{label=”UsedGB”; Expression={(($_.capacity - $_.freespace) / 1GB).tostring(“F0")}}, @{label=”FreeGB”; Expression={($_.freespace / 1GB).tostring(“F0")}}, @{label='Free%'; Expression={($_.freespace*100/$_.capacity).tostring(“F0”)}} >.\DisksSize.txt
<#
# Get-CimInstance Win32_volume | where-object { $_.DriveType -eq "3" } | Select-Object SystemName,Caption,Label,@{label = 'SizeGB';Expression = {($_.Capacity / 1GB).tostring("F0")}},@{label = 'FreeSpaceGB';Expression = {($_.FreeSpace / 1GB).tostring("F0")}} | ft -AutoSize
#>





Can you explain to me in simple terms what the script does?