2355
Comment:
|
3613
|
Deletions are marked like this. | Additions are marked like this. |
Line 11: | Line 11: |
|| Sort-Object -Property [property name] || Will sort the objects you send in by the property name(s) which can be a comma separated list || | |
Line 70: | Line 71: |
== List VMs at the end of the semester to be deleted == {{{#!highlight powershell Get-SCVirtualMachine | Select Name, MarkedAsTemplate, Owner | Sort-Object -Property Owner, Name | Export-Csv -Path .\vms2019w.csv }}} == Setting up a Windows 2019 Server for the first time == {{{#!highlight powershell # Install the AVMA key. slmgr /ipk TNK62-RXVTB-4P47B-2D623-4GF74 # Set the timezone # First I'm going to search for the timezone I want Get-TimeZone -ListAvailable | Where-Object {$_.DisplayName -like '*Eastern*'} # This gave me the parameter needed to set the time zone. Set-TimeZone -Name "Eastern Standard Time" # Set the Hostname of the computer: Rename-Computer -NewName "windows2019" -Restart # Next we need to install Windows update and get it started. # This will install nuget package too. Install-Module PSWindowsUpdate # Now start the update process Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot }}} Resources: * [[https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc#content|Powershell and Windows Update]] |
Here is a list of Power Shell Scripts that are too cool to ignore
Contents
For the uninitiated:
Symbol |
Meaning |
% |
shortcut for foreach object |
$_ |
current object in the pipeline |
Get-Member |
Will list the fields of the object you send it |
Sort-Object -Property [property name] |
Will sort the objects you send in by the property name(s) which can be a comma separated list |
Windows and AD Scripts
List of AD accounts and the last time they logged in
List Memory Installed
1 Get-WmiObject win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber -autosize
List object from Registry - namely version of .NET installed
1 gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | foreach-object {$_.name; $_.GetValue("Version");}
Remote commands
1 Invoke-Command -ComputerName eve -ScriptBlock { date }
Replace a string in a file using a regular expression
So I downloaded a bunch of files from "the way back machine" site and I needed to update the hard-coded links to be relative site links. The following little script did it for me.
SCVMM Powershell scripts
I needed this once when I was trying to refresh the Library share. It failed on refresh with an error saying that a DVD was in use and wouldn't refresh until it was no longer in use. The following commands allowed me to identify the machines.
In general all of these need:
1 Import-Module VirtualMachineManager
Get a list of Virtual Machines that have a DVD attached
List VMs at the end of the semester to be deleted
1 Get-SCVirtualMachine | Select Name, MarkedAsTemplate, Owner | Sort-Object -Property Owner, Name | Export-Csv -Path .\vms2019w.csv
Setting up a Windows 2019 Server for the first time
1 # Install the AVMA key.
2 slmgr /ipk TNK62-RXVTB-4P47B-2D623-4GF74
3
4 # Set the timezone
5 # First I'm going to search for the timezone I want
6 Get-TimeZone -ListAvailable | Where-Object {$_.DisplayName -like '*Eastern*'}
7 # This gave me the parameter needed to set the time zone.
8 Set-TimeZone -Name "Eastern Standard Time"
9
10 # Set the Hostname of the computer:
11 Rename-Computer -NewName "windows2019" -Restart
12
13 # Next we need to install Windows update and get it started.
14 # This will install nuget package too.
15 Install-Module PSWindowsUpdate
16
17 # Now start the update process
18 Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot
Resources: