Showing you how to effectively use parameters in PowerShell scripts, making your scripts more flexible and efficient. Whether you’re looking to automate user account management or want a deeper understanding of script execution, this video has got you covered.
Step By Step:
- Start by creating a PowerShell script that can create an admin account, either local or domain admin, based on the machine it’s being run on.
- If the script is run on a domain controller, it will create a domain admin account and generate a random password.
- Set the random password length between 16 and 21 characters.
- The script should be able to dynamically change the username, title, and display name of any user.
- The script should also update a password ID in Automate under the client, using the correct information, If the password ID already exists, it will use the existing password to deploy a custom password without generating a random string. The script will first check if the password ID or title provided exists in the system. If the password ID or title exists, it will use the existing password. If it doesn’t exist, the script will generate a random password and insert it into the database with the specified title.
- Write the actual PowerShell script to the machine, ensuring it will work to create a new domain or local admin, or update the password of an existing one.
- The script can be used to deploy a technician’s domain admin account across all machines, ensuring the correct parameters are provided.
- Redact the command history in the script (e.g., line 33) to hide the password in plain text for security reasons.
- Submit the password in plain text during the command execution, but redact it from the command history to avoid exposure.
- Encrypt the password fully using the password table to protect it.
- Update the password in the system or insert a new password entry into the database.
- After running the script and creating the domain or local admin account, clean up by deleting the folder where the script was stored on the machine.
- To ensure the script remains secure, avoid leaving it on the machine after use, as it could be used maliciously.
- If creating a PowerShell script that requires parameters, you can use a security application that excludes the script based on its hash.
- Create the script to ensure it doesn’t change, so security software can exclude its hash and allow it to run without being blocked.
- Add a “Generate Hashino” parameter to the script.
- Running the script with this parameter set to 1 will send an email containing the MD5 and SHA-256 hashes
- Use these hashes to exclude the script from being scanned by security software.
- Be aware that excluding the script from security software can pose a security risk, which is why it’s important to delete the script after use.
- Replace any special characters in the SQL commands to prevent interference with the insertion process.
- Replace random characters that could cause issues during importing with characters that won’t cause problems
- Finally, clean up by ensuring the folder containing the script is deleted, reducing the risk of the script being used maliciously.