Archivo de la etiqueta: powershell

Add AD to Existent Domain – Powershell

To Add a Write Controller to an existing Domain, first add Domain Services

Add-WindowsFeature AD-Domain-Services

Then install Role:

Install-ADDSDomainController -CreateDnsDelegation:$false -DatabasePath 'D:\Windows\NTDS' -DomainName 'MyExistentDomain.local' -InstallDns:$true -LogPath 'D:\Windows\NTDS' -NoGlobalCatalog:$false -SiteName 'MySite' -SysvolPath 'D:\Windows\SYSVOL' -NoRebootOnCompletion:$true -Force:$true -Credential (Get-Credential MyExistentDomain\AdminUser)


Thanks to Mike Robbins


Enable RDP Powershell Windows 2016

Only is needed three comands to enable RDP in powershell

New-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name 'fDenyTSConnections' -Value 0 -PropertyType dword -Force

To Enable RDP


New-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name 'UserAuthentication' -Value 1 -PropertyType dword -Force


To Enable NLA


Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'


To Enable on Firewall





Get-SCVMMInventory – Get Inventory of all VM’s in SCVMM 2012 R2

Credits are from Niklas AkerlundGet an inventory of all VM’s from System Center Virtual Machine Manager including the vCPU’s, memory, all VHD´s, IP addresses.  Report to CSV and HTML. Adapted to work with last actuallly SCVMM version 3.2.8224


Créditos son de Niklas AkerlundGet

Exportar un inventario de todas las VM’s es SCVMM. Se exporta a CSV y HTML, compatible con la última version 3.2.8224.


Get-SCVMInventory -report

Give a reports for “All Hosts”

Get-SCVMInventory -VMHost SERVER01

Give data from SERVER01 Hyper-v Host.

Publicado también en

   this function gives you an invetory of the SCVMM  
   either you can get just the object for each server or also a csv and html report 
   Get-SCVMInventory -report 
   Get-SCVMInventory -VMHost hyp05 
   Niklas Akerlund 2013-09-29 
   Adapted by Martin Rojas 2016/11/08 to version 3.2.8224.0 
function Get-SCVMInventory 
        $VMHostGroup = "All Hosts", 
        $VMHostCluster = $null, 
        $VMHost = $null, 
        [string]$path =".\", 
        [string]$CSVFile = "VMdata.csv", 
        [string]$HTMLReport = "VMdata.html" 
        if(!(Get-Module virtualmachinemanager)){ 
            Import-Module Hyper-V 
            Import-Module virtualmachinemanager 
        if(Get-SCVMMServer localhost | where ProductVersion -match 3){ 
            $isR2 = $true 
            $isR2 = $false 
         if ($VMHostCluster -eq $null){ 
            if($VMHost -eq $null){ 
                $VMHosts = (Get-SCVMHostGroup -Name $VMhostGroup).AllChildHosts 
                $VMHosts = Get-SCVMHost $VMHost 
            $VMHosts = (Get-SCVMHostCluster -Name $VMHostCluster).Nodes 
            $VMs = $VMHosts | Get-SCVirtualMachine 
            $reportArray = @() 
            foreach ($VM in $VMs){ 
                Write-Verbose $VM.Name 
                    $vNics = $VM.VirtualNetworkAdapters 
                    $VHDConf = $VM.VirtualHardDisks 
                    $driveConf = $VM.VirtualDiskDrives 
                    if(($vNics[0].IPv4Addresses -ne $null)){ 
                        Write-Verbose $vNics[0].IPv4Addresses[0] 
                        $IPAddress1 = $vNics[0].IPv4Addresses[0] 
                        if (!$isR2){ 
                            if(($vNics[0].IPv4Addresses -ne $null)){ 
                            $IPAddress1= (Hyper-V\Get-VMNetworkAdapter -ComputerName $VM.HostName -VMName $VM.Name).IPv4Addresses[0] 
                                $IPAddress1 = "N/A" 
                            Write-Verbose "NO IP" 
                            $IPAddress1 = "N/A" 
                    $Snapshots = "Yes" 
                    $Snapshots = "No" 
                    $data = [ordered]@{ 
                    VMName = $VM.Name 
                    vCPUs = $VM.CPUCount 
                    MemoryAssignedMB = $VM.MemoryAssignedMB 
                    Status = $VM.Status 
                    OperatingSystem = $VM.OperatingSystem 
                    HostName = $VM.HostName 
                     TotalSizeGB = $VM.TotalSize/1GB -as [int] 
                    vNics = $vNics.Count                                                          
                    VirtualNetwork1 = $vNics[0].VirtualNetwork 
                    MacAddressType1 = $vNics[0].MacAddressType 
                    MacAddress1 = $vNics[0].MacAddress 
                    VirtualNetworkAdapterType1 = $vNics[0].VirtualNetworkAdapterType 
                    VLANEnabled1 = $vNics[0].VlanEnabled 
                    VLanID1 = $vNics[0].VlanID  
                    IPAddress1 = $IPAddress1 
                    NumberofVHD = $VHDConf.Count 
                    VHDName = $VHDConf[0].Name 
                    VHDFormatType = $VHDconf[0].VHDFormatType 
                    VHDSize = $VHDconf[0].MaximumSize/1GB -as [int] 
                    VHDCurrentSize = $VHDconf[0].Size/1GB -as [int] 
                    VHDBusType = $driveConf[0].BusType 
                    VHDBus = $driveConf[0].Bus 
                    VHDLUN = $DriveConf[0].Lun 
                    VHDDatastore = $VHDconf[0].Directory 
                    VHDName2 = $VHDConf[1].Name 
                    VHDFormatType2 = $VHDconf[1].VHDFormatType 
                    VHDSize2 = $VHDconf[1].MaximumSize/1GB -as [int] 
                    VHDCurrentSize2 = $VHDconf[1].Size/1GB -as [int] 
                    VHDBusType2 = $driveConf[1].BusType 
                    VHDBus2 = $driveConf[1].Bus 
                    VHDLUN2 = $DriveConf[1].Lun 
                    VHDDatastore2 = $VHDconf[1].Directory 
                    VHDName3 = $VHDConf[2].Name 
                    VHDFormatType3 = $VHDconf[2].VHDFormatType 
                    VHDSize3 = $VHDconf[2].MaximumSize/1GB -as [int] 
                    VHDCurrentSize3 = $VHDconf[2].Size/1GB -as [int] 
                    VHDBusType3 = $driveConf[2].BusType 
                    VHDBus3 = $driveConf[2].Bus 
                    VHDLUN3 = $DriveConf[2].Lun 
                    VHDDatastore3 = $VHDconf[2].Directory 
                    StartMemoryGB = $VM.Memory/1024 
                    DynamicMemory = $VM.DynamicMemoryEnabled 
                    DynamicMemoryDemandMB = $VM.DynamicMemoryDemandMB 
                    DynamicMemoryStatus = $VM.DynamicMemoryStatus -as [int] 
                    DynamicMemoryMinMB = $VM.DynamicMemoryMinimumMB -as [int] 
                    DynamicMemoryMaxGB = $VM.DynamicMemoryMaximumMB/1024 -as [int] 
                    HasSnaphots = $Snapshots 
                    Owner = $VM.Owner 
                    Cloud = $VM.Cloud 
                    CreationTime = $VM.CreationTime 
                    HasVMAdditions = $VM.HasVMAdditions 
                    VMAddition = $VM.VMAddition 
            $obj= New-Object -TypeName PSObject -property $data 
            $reportArray +=$obj  
            Write-Output $obj 
                # $reportArray 
                $CSVReport = $path + $CSVFile 
                $HTMLReport = $path + $HTMLReport 
                $reportArray | Export-Csv -Path $CSVReport -NoTypeInformation -UseCulture 
                $reportArray | ConvertTo-HTML | Out-File $HTMLReport 
        # Should we clean anything?