Blog Image

Blog - Dries Willems - Freelance IT Consultant

About the blog

The main reason I use this blog, is to help myself tackling similar issues. You can see this as a very small online documentation library.
Also it is useful for others who experience the same issues.

GetLocalGroupsSID

Scripting Posted on 12/10/2018 14:25:55

$computerName = Read-Host ‘Enter computer name or press <Enter> for localhost’

$List = @{}

if ($computerName -eq “”) {$computerName = “$env:computername”}

$computer = [ADSI]”WinNT://$computerName,computer”

$Users = $computer.psbase.Children | Where-Object { $_.psbase.schemaclassname -eq ‘group’ }

foreach ($i in $Users)

{$objUser = New-Object System.Security.Principal.NTAccount($i.Name)

$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])

$list[$i.Name[0]] = $strSid.Value

}

$list | ft



Powershell – Get VM Names, Serial Number, Bios UUID

Scripting Posted on 11/11/2018 13:47:03

Get-WmiObject -Namespace root\virtualization\v2 -class Msvm_VirtualSystemSettingData | select ElementName, BIOSSerialNumber, BIOSGUID | Sort-Object -Property ElementName



Hyper-V VM Scripts

Scripting Posted on 02/01/2018 14:01:23

<#

ImportHyperVVM.ps1

Dries Willems

03/12/2014

#>

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All -NoRestart

Restart-Computer -Wait -For PowerShell -Timeout 600 -Delay 2

Import-Module Hyper-V

$ethernet = Get-NetAdapter -Name ethernet

$wifi = Get-NetAdapter -Name wi-fi

New-VMSwitch -Name EthernetExternalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

New-VMSwitch -Name WiFiExternalSwitch -NetAdapterName $wifi.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, wifi’

Copy-Item * C:\VM

Import-VM -Path ‘C:\VM\Cobra\Virtual Machines\6FAEE0C5-7422-45BD-A915-AA3C3A5D06A7.XML’

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

———————————————————————————————

<#

RenameStartVM.ps1

Dries Willems

03/12/2014

#>

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

———————————————————————————————

<#

CreateVSwitchImportRenameStartCobra.ps1

Dries Willems

03/12/2014

#>

Import-Module Hyper-V

#Create Virtual Switch

$ethernet = Get-NetAdapter -Name ethernet

$wifi = Get-NetAdapter -Name wi-fi

New-VMSwitch -Name EthernetExternalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

New-VMSwitch -Name WiFiExternalSwitch -NetAdapterName $wifi.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, wifi’

#Import VM

Import-VM -Path ‘C:\VM\Cobra\Virtual Machines\8F300942-505B-41C0-8644-B46321581214.XML’

#Rename VM & Start

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

——————————————————————————————–Cobra.bat

Powershell.exe -executionpolicy bypass -File .\CreateVSwitchImportRenameStartCobra.ps1

xcopy “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Hyper-V Management Tools\VMConnect.lnk” “C:\Users\Public\Desktop\Hyper-V Virtual Machine Connection.lnk”* /I /S /Y /C /R



How to add all users in an OU to a Security Group using Get-ADUser and Add-ADGroupMember

Scripting Posted on 07/01/2015 15:46:39

Get-ADUser -SearchBase ‘OU=DEV,OU=BuitenDienst,OU=Users,OU=Moto,DC=Com’ -Filter * | ForEach-Object {Add-ADGroupMember -Identity ‘GG_SDS_DEV_Caris_ML_PROD’ -Members $_ }

http://oxfordsbsguy.com/2015/03/09/powershell-how-to-add-all-users-in-an-ou-to-a-security-group-using-get-aduser-and-add-adgroupmember/



Change Statuscode 3010 to 0

Scripting Posted on 06/15/2015 15:19:33

@echo off

msiexec /I vc_red.msi TRANSFORMS=vc_red.mst /qn ALLUSERS=1 /L*v %windir%\temp\TEST_SDS_Microsoft_VC++RedistSU_2008SP1_1.0_EN_x86_Inst.log REBOOT=REALLYSUPPRESS

if %errorlevel% == 3010 (exit /b 0) else (exit /b %errorlevel%)



SetUsersFullControl.ps1

Scripting Posted on 02/13/2015 15:03:49

$sharepath = “C:\SWL”

$Acl = Get-ACL $SharePath

$AccessRule= New-Object System.Security.AccessControl.FileSystemAccessRule(“Users”,”full”,”ContainerInherit,Objectinherit”,”none”,”Allow”)

$Acl.AddAccessRule($AccessRule)

Set-Acl $SharePath $Acl