Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Tuesday, June 27, 2017

Server 2012 R2 Evaluation won't register

Building new server you run into things sometimes that are annoying or weird. One of those can registration and activation. 

Building some new 2012 R2 Standard server and I couldn't register the server. It kept saying the activation code was wrong. 

Well there is a VERY easy fix for this. 

I found it here.
https://social.technet.microsoft.com/Forums/windows/en-US/4211c642-b15d-49ea-8124-f0628aa0f92e/activate-windows-server-2012-evaluation-standard-version-with-a-product-key-oem?forum=winserver8gen&prof=required

Run this code to change it from evaluation.

DISM /online /Set-Edition:<edition ID> /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX /AcceptEula


Change <edition ID> to the edition you have the licence for eg.

DISM /online /Set-Edition:ServerStandard /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX /AcceptEula

You will need to reboot, so keep that in mind. 

The one thing that the source where i found this doesn't tell you is, you still need to activate your server with your key. 

So go to the Server Manager > Local Server > Properties > Click Activate next to Product ID > Enter your information.

Enjoy.


Friday, March 20, 2015

Get a list of IPs VIA System.Net.Dns

So needed to look up more IPs via scripts again. The last script I used worked great but didn't grab everything because of the environment I am in. So I took the rest of the systems I needed IPs for and noticed I could use nslookup to get the IPs. Of course nslookup is not made for automation so I went looking again. And again powershell came to the rescue.

In the System.Net.Dns Class.

The script i found came from this website.
http://community.spiceworks.com/scripts/show/1201-powershell-script-dns-forward-lookup-script-with-auto-generate-excel-file

Here is the script from that page. It basically grabs a list of names, or ips from text file you supply and it spits back out into an excel document.. SWEEET...


 ###########################################################################
#
# NAME: DNS Forward Lookup Script with Auto Generate Excel File
#
# AUTHOR: J.Malek (www.malekjakir.com) Email: malek dot one zero four zero at gmail dot com
#
# COMMENT: This script can be used to check list of Servers for Forward NSLookup to get the IP Addresses.
# Line#29 - Please Change the path of Servers.txt to your file location.
# NOTE: One server name per line.
#
# VERSION HISTORY:
# 1.0 2/17/2012 -
#
###########################################################################
$ErrorActionPreference = "silentlycontinue"

$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "Server Hostname"
$c.Cells.Item(1,2) = "IP Address"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2

$colComputers = get-content "C:\SCRIPTS\DNS_Lookup\ForwardLookup\Servers.txt"
foreach ($strComputer in $colComputers)
{
$FWDIP = [System.Net.Dns]::GetHostAddresses($strComputer) | Add-Member -Name HostName -Value $strComputer -MemberType NoteProperty -PassThru | Select HostName, IPAddressToString

$c.Cells.Item($intRow,1) = $FWDIP.Hostname
$c.Cells.Item($intRow,2) = $FWDIP.IPAddressToString
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls
Write-Host "######## This Script is completed now ########"
Thank you internet..


Monday, December 2, 2013

Gimme all the Groups and their users

Issue:

I need a list of  all of the user groups from a system and what users are inside of them.

Now I notice that there are not just users, there are users both local and domain, and also possible other groups. The domain part is interesting. Also the groups in a group poses a problem. It doesn't give me the user.

Problems?

Well of course there were problems.
a. The servers i needed to talk to are locked down tighter than Uncle Scrooges coin purse. So no getting the information remotely. 

The resolution 1:

Make a script to export this information. I ultimately ended up using VBScript as i usually end up doing for these types of scripts. After some googling and stitching together of some code I ended up with this. It is a script that dumps a tab delimited text file to your desktop of all the groups with their users/groups listed. 

The Code 1:

'Set the var objShell to run shell commands against
Set objShell    = CreateObject("WScript.Shell")



'Set the var userProfilePath using previous shell variable to get the users profile path
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%")



'Set the var wshNetwork to equal the network object
Set wshNetwork  = WScript.CreateObject"WScript.Network" )



'Set the var strComputerName as the computers name using the previous network object var
strComputerName = wshNetwork.ComputerName



'Set where to dump th txt file too.
outFile  = userProfilePath & "\desktop\output1.txt"



'Create the file the "true" flag is there to overwrite the file if it exists.
Set objFile = objFSO.CreateTextFile(outFile,True)



'Create variables to be used later
Dim host
Dim group
Dim member



'Set the host, computer name, to be used to look up the. Since i do not have network access I just use localhost.
host = "localhost"



'Loop through the results of GetObject to get all the "groups"

For Each group In GetObject("WinNT://" & host)



'Self-explanatory
If group.Class = "Group" Then
  


'Loop through the members of that group to get a list of the members
  For Each member In group.members
  


'write the computer name, group and its members to the txt file. 
   objFile.Write strComputerName & vbTab & group.name & vbTab & member.name & vbCrLf
  


'Go to the next member till no more members in that group
  Next
  


'End the if statement if  the group class is not a group class type.
End If




'End the loop of  all the class objects.
Next

Problems #2?

I need the FULL list of users. Lets see if we can get a list of users from the groups of the groups we just pulled from.. umm.. could this turn into an infinite loop?

Info finding:

So after the "For Each member In group.members" i did some digging after finding some other properties i could dig into.

I am using WScript.Echo member.? to get the information.. so like WScript.Echo member.class

class =  the class of the object, such as; user and group

AdsPath = gives the path of the object..
Formatted like: WinNT://pathName/objectName
Example: WinNT://MyComputer21/Bob

Name = the name of the object.. like the name: Bob

Parent = This one gives where the object comes from.. this i want..
Formated like WinNT://location
Example: Domain = WinNT://MICROSOFT
               Machine = WinNT://MyComputer21