Archive for the ‘Powershell’ Category

Get #windows 10 digital license with #Powershell #winserv #OSD #WDS   1 comment

When rebuilding your windows 10 desktop that hold a digital license key there is no piece of paper that tells you the activation key.

with the following command you can read the product key

$service = get-wmiObject -query ‘select * from SoftwareLicensingService’
$service.OA3xOriginalProductKey
$key=$service.OA3xOriginalProductKey

this is handy for getting the key but when you are deploying a WDS image and everything needs to be unattended you will need a little PowerShell script

As an option there to place a different key for if you are in a mixed environment.

$service = get-wmiObject -query ‘select * from SoftwareLicensingService’
$service.OA3xOriginalProductKey
$key=$service.OA3xOriginalProductKey
$service.InstallProductKey($key)

$service = get-wmiObject -query ‘select * from SoftwareLicensingService’
if($key = $service.OA3xOriginalProductKey){
    Write-Host ‘Activating using product Key:’ $service.OA3xOriginalProductKey
    $service.InstallProductKey($key)
}else{

    #Write-Host ‘Key not found., use a different license’
       # $service.InstallProductKey(‘Put your License KEY here’)
}

 

Save this as a Powershell script and put this in the unattended.xml and when deploying the Windows 10 will be auto activated

Get the script from the site or from the TechNet gallery.

https://gallery.technet.microsoft.com/Get-windows-10-digital-7653fae4

 

Follow Me on Twitter @ClusterMVP

Follow My blog https://robertsmit.wordpress.com

Linkedin Profile Http://nl.linkedin.com/in/robertsmit

Google Me : https://www.google.nl

Bing Me : http://tinyurl.com/j6ny39w

LMGTFY : http://lmgtfy.com/?q=robert+smit+mvp+blog

Posted March 19, 2017 by Robert Smit [MVP] in Powershell

Tagged with

Powershell Management Commands Easy Step by Step get Server info in HTML ConvertTo-   Leave a comment

Powershell is a great way to get your server info. like a poor mans management Tool.

I will explain the ConvertTo command easy to use and with a scheduler it can be very handy.

And I will show several Powershell commands that can be handy to find things.

 

What is the Converto- ?

The ConvertTo-Html cmdlet converts .NET Framework objects into HTML that can be displayed in a Web browser. You can  use this cmdlet to display the output of a command in a Web page.

You can use the parameters of ConvertTo-Html to select object properties, to specify a table or list format, to specify the HTML page title, to add text before and after the object, and to return only the table or list fragment, instead of a strict DTD page. When you submit multiple objects to ConvertTo-Html, Windows PowerShell creates the table (or list) based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties,  the property value of that object is an empty cell. If the remaining objects have additional properties, those property values are not included in the file.

Some Samples to get things working

get-service A*  this shows all the services starting with an A

image Or in the full context

get-service A* | ConvertTo-Html -title "Windows Services: Server01" -body (get-date) -pre "<P>Generated by Corporate IT</P>" -post "For details, contact Corporate IT." > services.htm; ii services.htm

imagenow that you can get the info in HTLM , you can place the info in a webserver and on a collection page you can see the status of your server.

imageimage

Get-Service  <> shows the full list

get-service | ft -Property name, status  <>or in a table

get-service | where-object {$_.Status -eq "Running"}   <> shows only the running services. or the stopped services

imageimage

 

Now the disk info.

get-psdrive  Or get-psdrive | where-object {$_."Free" }  it shows the free space.

imageimage 

 

get-hotfix | where-object {$_.HotFixID -eq ‘KB982293’ }  <> get hotfix list

image

get-process | where-object {$_.Handles -gt ‘888’ }  <> Shows process with more handles than 888 Change the value for other items

image

 

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ }

image for other disk change the C or F value

Get-ClusterNetworkInterface

image

Get-ClusterNetworkInterface | where-object {$_.State -eq ‘Up’ } <> or down

Get-ClusterNetworkInterface | where-object {$_.State -ne ‘Up’ }  

image

 

Now that we have a basic set of command we will use this in the convertTo-HTML to get the output in html.

 

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -as Table "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01</P>" > Listdisk.htm; ii ListDisk.htm

creates the site and in ii it opens the site.

image  imageimage

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -as Table -Title "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01</P>" > Listdisk.htm; ii ListDisk.htm

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -as list -Title "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01</P>" > Listdisk.htm; ii ListDisk.htm

 

 

 

There are several options for the listing format play with it and get your perfect list.

get-service A* | ConvertTo-Html -title "Windows Services: Server01" -body (get-date) -pre "<P>Generated by Corporate IT</P>" -post "For details, contact Corporate IT." > services.htm; ii services.htm

imageimage

get-service | where-object {$_.Status -eq "Stopped"} | ConvertTo-Html -title "Windows Services Stopped on ServerName " -body (get-date) -pre "<P>Generated On Myserver01 </P>" > servicesstoped.htm; ii servicesstoped.htm

get-psdrive | where-object {$_.Name -like ‘C’ -Or $_.Name -like ‘F’ } | ConvertTo-Html -title "List C drive and F drive" -body (get-date) -pre "<P>Generated On Myserver01 </P>" > Listdisk.htm; ii ListDisk.htm

 

image

 

In the basic you can get any info and create a html file.

Technorati Tags: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
WordPress Tags: Powershell,Management,Commands,Easy,Step,Server,info,HTML,ConvertTo,Tool,Converto,Framework,objects,output,text,cell,Some,services,context,Corporate,HTLM,collection,status,Service,disk,Free,HotFixID,Change,items,Name,ClusterNetworkInterface,State,Table,List,Listdisk,Title,ServerName,parameters,options,cmdlet,psdrive,hotfix

Posted July 25, 2011 by Robert Smit [MVP] in Powershell, ServerManagement

Create IIS NLB Copy Full Website Resource Windows 2008R2 With Powershell   Leave a comment

If you are Building a Webfarm you need often Test websites and all the Sites needs to be the same Winking smile

Well below is a powershell Scripts that copy the Site and Creates a new one On the Same Server.

 

# NAME: Copy-Website.ps1
#
# AUTHOR: Robert Smit
# EMAIL: robert.smit@aca-computers.nl
#
# COMMENT: Script to create a Copy-Website.
#   
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 4.06.2011 – Initial release
#
###########################################################################
ImportSystemModules
#Importing Microsoft`s PowerShell-modules

#Set ExecutionPolicy
#Set-ExecutionPolicy -scope LocalMachine RemoteSigned –force

#Importing Microsoft`s PowerShell-module for administering IIS
Import-Module WebAdministration

#List website
Write-Host "List IIS Website…" -ForegroundColor yellow
get-Item IIS:\Sites\*

#Variables for creating the new Website
#
#
$sourceweb = Read-Host "Enter the Website to Copy"
$destinationweb = Read-Host "Enter the New Websitename"
$ChangedDemoSiteBinding = Read-Host "Enter the Hostheader of the website"
$LogDir = Read-Host "Enter the website path of the new website"

#Copy website
Write-Host "copy IIS Website…" -ForegroundColor yellow
copy-Item IIS:\Sites\$sourceweb -destination IIS:\Sites\$destinationweb

#Create Application pool
Write-Host "Create Application pool…" -ForegroundColor yellow
New-WebAppPool $destinationweb

#Link Application pool
Write-Host "Link Application pool…" -ForegroundColor yellow
get-ItemProperty IIS:\Sites\$destinationweb
Set-ItemProperty IIS:\Sites\$destinationweb -name applicationPool -value "$destinationweb"

#Set nieuwe Host name
Write-Host "Set nieuwe Host name…" -ForegroundColor yellow
get-Item IIS:\Sites\$destinationweb
Set-ItemProperty IIS:\Sites\$destinationweb -Name bindings -Value @{protocol="http";bindingInformation="192.168.123.1:80:$ChangedDemoSiteBinding"} #change the IP here

#Set new Path
Write-Host "Set new Path…" -ForegroundColor yellow
get-Item IIS:\Sites\$destinationweb
Set-ItemProperty IIS:\Sites\$destinationweb -Name physicalPath -Value "$LogDir"

#Scopy site
#Write-Host "Scopy site …" -ForegroundColor yellow
#Copy-Item "C:\Put your folder here\*" $LogDir # change The Filepath here

#Set user account
Write-Host "Set user account…" -ForegroundColor yellow
Set-ItemProperty IIS:\Sites\$destinationweb -Name Username -Value "Username"
Set-ItemProperty IIS:\Sites\$destinationweb -Name Password -Value "Password"

Posted June 27, 2011 by Robert Smit [MVP] in Powershell, Webfarm, Windows 2008 NLB

Tagged with

Create Services Cluster Resource Windows 2008R2 With Powershell   Leave a comment

In a Cluster You can cluster Services this can be done by the wizzard Or with Powershell.

Below a easy powershell script to create a clustered services.

In my case I used the altiris Services You can adjust this whit any services You like.

Add-ClusterGroup -Name AltirisGroup
Add-ClusterResource -Name Altiris -Resourcetype "Generic Service" -group AltirisGroup
Get-ClusterResource -Name Altiris |Set-ClusterParameter -Name ServiceName -value "Altiris Deployment Agent"
Get-ClusterResource -Name "Altiris" |Set-ClusterParameter -Name StartupParameters -value "C:\Program Files\Altiris\Dagent\dagent.exe"

Powershell MSDTC cluster add in   1 comment

Teched 2010 Berlin #TEE10 #Teched

For Demo and learning Sites you need often thing that takes only a minute but when you play with it it takes more time than you want.

So with this in my mind I created 3 powershell scripts that you can use for builing a cluster , NLB Cluster and a MSTDC cluster resource.

So If you want to create a MSDTC resource in your Cluster you can do this in the GUI or with a Powershell Script.

You can find the Scripts Here : Powershell Scripts

Powershell MSDTC cluster add in

First We load the powershell modules If it is a cluster you should do this on all the Cluster Nodes

Servermanagercmd -install Application-Server
Servermanagercmd -install AS-Dist-Transaction AS-Ent-Services –allSubFeatures

I Comment every line for what it does.

# Create a new HA Server Role – Distributed Transaction Coordinator
Add-ClusterServerRole -Name ServerDTC -Storage "Cluster Disk 6" -StaticAddress 192.168.1.1

Here we create the resource and chuck it to a disk and IP

# Add the MSDTC Service to the new Server Role
Get-ClusterGroup ServerDTC | Add-ClusterResource -Name MSDTC-ServerDTC -ResourceType "Distributed Transaction Coordinator"

Put in the MSDTC services.

# Create Dependencies for the DTC group
Add-ClusterResourceDependency MSDTC-ServerDTC ServerDTC
Add-ClusterResourceDependency MSDTC-ServerDTC "Cluster Disk 6"
# Start DTC group
Start-ClusterGroup ServerDTC

 

So Now that this is ready you can configure the MSDTC but remember the items that I mentioned in my previous blog.

https://robertsmit.wordpress.com/2010/10/20/msdtc-clustering-logfile-bug/

  • Twitter

  • %d bloggers like this: