Scripts for generally working with windows boxes, usually WinPoSh 5.1
Function to add an account to the local Admin and remote access groups
by Steven Wight
Add-UserToLocalGroups -Hostname <Computername, -User <Domain/username> Default = can be set -Domain <Domain> Default = can be set
Add-UserToLocalGroups Computer0454S
Defaults can be added in the parameters part, I made this as sometimes I have to use RDP instead of citrix or my Test account needs local Admins for some testing/ etc..
Our GP will nuke them when it refreshes so is just for temp work and I don't need to worry about removing them (usually bounce box when finished)
Function to start and and set to auto service
by Steven Wight
Enable-Service -Hostnames <Computername>, SVC <Service Name> -Domain <Domain> Default = POSHYT
Enable-Service Computer0454S Spooler, Get-content c:\temp\hostnames.csv (or.txt) | Enable-Service Spooler
run against one machine = Enable-Service Computer0454S Spooler or a list = Get-content c:\temp\hostnames.csv (or.txt) | Enable-Service Spooler
Function to stop and disable service
by Steven Wight
Disable-Service -Hostnames <Computername>, SVC <Service Name> -Domain <Domain> Default = POSHYT
Disable-Service Computer0057P Spooler, Get-content c:\temp\hostnames.csv (or.txt) | Disable-service Spooler
run against one machine = Disable-Service Computer0057P Spooler or a list = Get-content c:\temp\hostnames.csv (or.txt) | Disable-Service Spooler
Function to pull Hardware & OS info from a machine (prints to console and passes out object with data)
by Steven Wight
Get-HardwareOSInfo -ComputerName <Hostname> -Domain <domain> (default = POSHYT)
Get-HardwareOSInfo Computer01
You may need to edit the Domain depending on your environment (find $Domain)
Function to correct wrong time and date on remote machines
by Steven Wight
Correct-SystemTime -ComputerName <Hostname> -Domain <domain> (default = POSHYT)
Correct-SystemTime Computer01
This assumes the correct time and date on the machine it's being run from
Still to turn this into a function, at the moment, make sure the first line is pointing at the required domain you want to fire it against, put the name of the process you want to find in $processName, make sure $Outfile and $ErrorLog are pointing at a valid location and run, It will extract all the machines on the domain and run through them, wrote this as we had a bespoke app that "mostly" lives on a filesshare, it has a start up script the users fire and it read a config file and then starts going. sometimes this start script hangs and locks out the config file and this is the way to find the offending machine without having to pester the Server team.
Okay this is the above as a function, However is been aimed at one app called UnstableAtom. It will search a list of hostnames , if it finds the process on the machine it pulls details of machine and logged in user, it will also prompt you to kill the process, it will kill and check, if the issue still persists (the application can't be launched becuase a stalled process is locking out the startup script on the file/app share) for usage, you needs RSAT installed on machine as it uses AD module. To edit, look for parameters around line 307, also get logged in user details ( 207: Get-LoggedonUsersDetails) extracts a username and domain via spliting a string, you may need to play with that (also check fiedls from AD I pull out), for help file, get-help Kill-UnStableAtomStartupScript -full