Differences between revisions 1 and 10 (spanning 9 versions)
Revision 1 as of 2020-08-13 04:15:41
Size: 631
Editor: PieterSmit
Comment:
Revision 10 as of 2021-10-10 22:41:30
Size: 2359
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
 * [[Windows/PowerShell/AddCsvEmailToAdGroup]]
 * Load context {{{
foreach($server in (get-content 'C:\Downloads\pilot_dev_servers.txt')){Get-ADComputer -Identity $server | select -ExpandProperty DistinguishedName}
}}}
Line 4: Line 8:
 * 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
}}}
Line 9: Line 21:
 * Reason missing admin module
 * Fix
   * http://blog.technotesdesk.com/active-directory-module-and-cmdlet-missing-upon-patching
     * RSAT tool https://www.microsoft.com/en-us/download/details.aspx?id=45520
   * Reason missing admin module {{{ get-module -listavailable }}}
   * Fix
     * http://blog.technotesdesk.com/active-directory-module-and-cmdlet-missing-upon-patching
       * RSAT tool https://www.microsoft.com/en-us/download/details.aspx?id=45520
         * After install still got import error {{{
> import-module activedirectory
WARNING: Error initializing default drive: 'Unable to find a default server with Active Directory Web Services
running.'.
}}}

= 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
}}}

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

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

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