Run MSI from PowerShell script with spaces in directories

Make use of double “” to add a single ” in a variable for paths that has spaces

C:\Program Files (x86)\ThunderBolt 3 Update

$ExportPath = ${Env:ProgramFiles(x86)} + "\ThunderBolt 3 Update"
Write-Log "Detecting Thunderbolt Driver Version"
$TBTDriverVersion = (Get-WmiObject Win32_PnPSignedDriver | Where-Object { $_.DeviceName -like "*Thunderbolt(TM) Controller*" }).driverversion
	if ($null -eq $TBTDriverVersion) {
		try {
                    Write-Log "Thunderbolt Driver not found"
                    $InstallCmd = "$ExportPath\SW\$CSVCMDSW"
                    $InstallCmdLog = "/l*v ""$ExportPath\Install_SW.log"""
                    $InstallCmdComplete = "/i ""$InstallCmd"" /qn"

                    Write-Log "Installing Thunderbolt Software"
                    $InstallTBTSoftware = Start-Process -FilePath msiexec.exe -ArgumentList $InstallCmdComplete -Wait 
                }                
                catch {
                    Write-Log "Thunderbolt Software installation failed "$InstallTBTSoftware.ExitCode". Logs located at $ExportPath"
                    Write-Log "----------------------------- End Script ------------------------------"
                    Exit
                }

GetLocalGroupsSID

$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

Hyper-V VM Scripts

<#

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

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/