Differences between revisions 13 and 14
Revision 13 as of 2022-01-26 08:19:45
Size: 2832
Editor: PieterSmit
Comment:
Revision 14 as of 2022-01-26 21:34:01
Size: 3074
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 74: Line 74:

== PowerShell update host file with dns entry ==
{{{
Add-Content -Path $env:windir\System32\drivers\etc\hosts -Value "`n127.0.0.1`tlocalhost" -Force
#

}}}
 * Scripts to manipulate host files https://github.com/TomChantler/EditHosts

Windows/PowerShell Notes

  • Windows/PowerShell/AddCsvEmailToAdGroup

  • Load context

    foreach($server in (get-content 'C:\Downloads\pilot_dev_servers.txt')){Get-ADComputer -Identity $server | select -ExpandProperty DistinguishedName}

Missing powershell commands

  • e.g. get-content missing, search https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-Content?view=powershell-7

    • its in  Import-Module Microsoft.PowerShell.Management 

  • Get info on a machine by id

    #Powershell > import-module activedirectory
                  Get-ADComputer -Identity "abcd" | select -ExpandProperty DistinguishedName
  • test tcp connectivity to port

    PS C:\Users\Administrator> tnc 10.233.1.47 -port 443
    ComputerName     : 10.23.1.47
    RemoteAddress    : 10.23.1.47
    RemotePort       : 443
    InterfaceAlias   : Ethernet 2
    SourceAddress    : 10.23.8.186
    TcpTestSucceeded : True
  • Err

    > Get-ADComputer -Identity "abcd" | select -ExpandProperty DistinguishedName
    Get-ADComputer : The term 'Get-ADComputer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1

PowerShell view user certificates

  • > Get-ChildItem -Path "Cert:\CurrentUser\My"
    
    
       PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
    
    Thumbprint                                Subject
    ----------                                -------
    ...

PowerShell windows update on remote computer

  • Have to do it through a job

    ServerData = "<ServerName>"
    invoke-WUJob -ComputerName $ServerData.Value -Script { Import-Module PSWindowsUpdate ; Install-WindowsUpdate -AcceptAll -SendReport -IgnoreReboot -PSWUSettings @{From='xy';Port=25;SmtpServer='xy';To='xy'} | Out-File C:\install\PSWindowsUpdateLog.txt -Append} -Confirm:$false -verbose -RunNow

PowerShell add admin user

net user mylocaladmin p@ssw0rd! /add /expires:never
net localgroup administrators mylocaladmin /add

PowerShell unlock user

 Set-LocalUser -name '<userid>' -PasswordNeverExpires $true

PowerShell reset user password e.g. Administrator

net user USERNAME NEWPASS

PowerShell update host file with dns entry

Add-Content -Path $env:windir\System32\drivers\etc\hosts -Value "`n127.0.0.1`tlocalhost" -Force
#

Windows/PowerShell (last edited 2022-01-26 21:34:01 by PieterSmit)