Skip to content

Instantly share code, notes, and snippets.

View simstems's full-sized avatar

Stephen Morrison simstems

View GitHub Profile
@simstems
simstems / RenameRemote.ps1
Created August 15, 2025 15:55
Rename a remote Windows computer using PowerShell.
Rename-Computer -ComputerName "Srv01" -NewName "Server001" -LocalCredential Srv01\Admin01 -DomainCredential Domain01\Admin01 -Force -PassThru -Restart
<#
1. Use -LocalCredential when: The computer is not joined to a domain yet (workgroup machine), or you are renaming it before joining it to a domain.
2. Use -DomainCredential when: The computer is already domain-joined and you are renaming it while it’s on the domain.
3. Use both -LocalCredential and -DomainCredential when: The computer is domain-joined, but you don’t currently have a session with domain rights to the remote system meaning:
@simstems
simstems / RemoteUpdateList.ps1
Last active August 12, 2025 19:32
Run updates on a list of remote systems.
$namesList = @(
"[PC-NAME]",
"[PC-NAME]",
"[PC-NAME]",
)
foreach ($name in $namesList) {
Enter-PSSession -ComputerName $name
gpupdate /force
# Install-Module -Name PSWindowsUpdate -Force
@simstems
simstems / RemoteRestartList.ps1
Created August 11, 2025 21:15
Restart a list of remote computers.
$namesList = @(
"[PC-NAME]",
"[PC-NAME]",
"[PC-NAME]",
)
foreach ($name in $namesList) {
shutdown /r /m \\$name /t 0
}
@simstems
simstems / Ex2Ex.txt
Created July 31, 2025 21:52
Explorer to Explorer
How to access another Windows computer's file explorer from file explorer:
\\ComputerName\C$
@simstems
simstems / Local-Admin.ps1
Created July 21, 2025 13:16
Add user ad local administrator
Add-LocalGroupMember -Group "Administrators" -Member "DomainName\UserName"
@simstems
simstems / Get-Drive-Info.ps1
Created July 17, 2025 16:36
Drive Info Commands
Get-PhysicalDisk | Select-Object DeviceID,FriendlyName,MediaType,BusType,@{Name='Size(GB)';Expression={"{0:N1}" -f ($_.Size/1GB)}} | Format-Table -AutoSize
Get-Partition | Format-Table -AutoSize
@simstems
simstems / Re-PW-Session.ps1
Created July 17, 2025 13:35
Traverse windows directory on remote computer via PowerShell
Enter-PSSession -ComputerName <RemoteComputerName> -Credential (Get-Credential)
<#
Invoke-Command -ComputerName REMOTEPC -ScriptBlock {
Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name, Manufacturer, Model
Get-CimInstance -ClassName Win32_BIOS | Select-Object -ExpandProperty SerialNumber
}
#>
Invoke-Command -ComputerName REMOTEPC -ScriptBlock {
Invoke-Command -ComputerName <RemoteComputerName> -ScriptBlock {
Import-Module PSWindowsUpdate
Get-WindowsUpdate -AcceptAll -Install -AutoReboot | Out-File C:\Windows\PSWindowsUpdate.log
}
Enter-PSSession -ComputerName <servername>
gpupdate /force
# Install-Module -Name PSWindowsUpdate -Force
Import-Module PSWindowsUpdate
Get-WindowsUpdate
Install-WindowsUpdate -AcceptAll -AutoReboot
# Restart-Computer -Force