-
Notifications
You must be signed in to change notification settings - Fork 0
Lab10Powershell
In Powershell you can set aliases which run certain commands as if you had typed their true name. You can do this like so:
Set-Alias -Name ifconfig -value ipconfig
- This only works for the session you are currently in. If you want this is be persistent you will need to research Powershell Profiles
You can also search for the definitions of an alias like dir like so:
alias dir - this will output what dir points to, which in this case is Get-ChildItem (this is what will actually run)
Scripts in powershell are called .ps1 and work very similarly to bash scrips, with slightly different syntax. In order to run scripts you will need to run the following command:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
- This will allow current users to run local scripts
You can use PSSession to remote into a computer via powershell, like so:
Enter-PSSession -ComputerName FS01-ELIZABETH
(Tip: to show computers in the domain run the command Get-ADComputer -Filter * | Select-Object Name - This shows only the names of the computers in the domain)
You can also invoke a command on a computer. The following uses this to run ipconfig on FS01-ELIZABETH:
Invoke Command -ComputerName FS01-ELIZABETH -ScriptBlock { ipconfig }
In order to create a new AD User named "Bobette" in the group "PowershellUsers," I used the following command:
New-ADOrganizationalUnit -Name "PowershellUsers" -Path "DC=elizabeth,DC=local"; New-ADUSer -Name "Bobette" -SamAccountName "bobette" -Path "OU=PowershellUsers,DC=elizabeth,DC=local"
- This creates a new AD OU under the domain elizabeth.local named "Powershell Users," and then creates a new AD user named Bobette in that new OU
I was having some trouble with this, but I think that's because I forgot to run Powershell as an Administrator. That and it was possible I was passing parameters that I didn't totally understand and that may have been causing issues.
In order to enable PSSession on WKS02 I had to run a command on the workstation to explicitly allow this:
Enable-PSRemoting -Force
I was having some problems connection to WKS02 from AD02, and eventually figured out that WKS was not allowing inbound pings, so I had to go into the firewall and enable that so I could connect to WKS from AD. I was able to ping AD from WKS, but not the other way around