Tag Archives | Windows

My WSL/BASH setup

Not sure if this a “Bootstrap” or not, but I wanted to have my WSL/Bash home directory match my windows home directory. This is the code that I use when I setup a new WSL/BASH instance.

This will find your home directory via PowerShell and put it in a variable “$WINHOME”.

Then I make make soft links to the directories in my “My Documents”.

Finally, I add the first part to my .bashrc. (lines 1-4)


WINHOME=/mnt/$(powershell.exe -noprofile -noninteractive -command '& {(gci env:USERPROFILE).Value}')
WINHOME=$(echo $WINHOME | sed 's/\\/\//g' | sed 's/\r$//' | sed 's/\://g' )
WINHOME=$(echo ${WINHOME/C/c})
export WINHOME=$WINHOME

ln -s $WINHOME/Documents
ln -s $WINHOME/Downloads
0

Windows 10 PinToTaskbar does not work

More Windows 10 fun. Trying to get a nice customized image for deployment. In the past I have used the verb “taskbarpin” and a RunOnce script to put icons on the users Task Bar.
For example:

$ShellApplication = New-Object -ComObject Shell.Application
$result=$ShellApplication.Namespace("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office").ParseName("Microsoft Outlook 2010.lnk").InvokeVerb("taskbarpin")
$result=$ShellApplication.Namespace("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office").ParseName("Microsoft Word 2010.lnk").InvokeVerb("taskbarpin")
$result=$ShellApplication.Namespace("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office").ParseName("Microsoft Excel 2010.lnk").InvokeVerb("taskbarpin")
$result=$ShellApplication.Namespace("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office").ParseName("Microsoft PowerPoint 2010.lnk").InvokeVerb("taskbarpin")

Well, with the current build/set of patches, it no longer works. That was a waste of a day!

Here is the bug filed with Microsoft Connect:

Pint To Taskbar no longer working

Hope that helps someone.

Using PowerShell to unpin the AppStore in Windows 10 – Workaround

I can’t find a way to unpin the AppStore in Windows 10. So I wen’t about it another way.
I reset the taskbar to have nothing and then I added everything back that I wanted.
I am using this in my OSD/RunOnce PowerShell script to customize the user’s desktop.

First of all I am using this function to manipulate the registry:

Function ChangeRegistry{
PARAM(
$ErrorActionPreference = "SilentlyContinue",
[Parameter(Mandatory=$true)]$registryPath,
[Parameter(Mandatory=$true)]$Name,
[Parameter(Mandatory=$true)]$Value ,
[Parameter(Mandatory=$true)]$PropertyType,
$Comment
)
Try {
 $RESULT=Get-ItemProperty -Path $registryPath -Name $Name | Out-Null
 New-ItemProperty -Path $registryPath -Name $Name -Value $Value -PropertyType $PropertyType -Force | Out-Null
}
Catch [System.Management.Automation.PSArgumentException] {
  New-ItemProperty -Path $registryPath -Name $Name -Value $Value -PropertyType $PropertyType -Force | Out-Null 
}
Catch [System.Management.Automation.ItemNotFoundException] {
  New-Item -Path $registryPath -Force | Out-Null
  New-ItemProperty -Path $registryPath -Name $Name -Value $Value -PropertyType $PropertyType -Force | Out-Null 
}
Finally { 
$ErrorActionPreference = "Continue" 
Write-host "$($Comment)$($Name): $Value"
}
}

Next I reset the Taskbar:

Write-Host "Setting up Start Menu" -ForegroundColor Green
ChangeRegistry -registryPath "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "Favorites" -PropertyType "Binary" -Value ([byte[]](0xFF))
ChangeRegistry -registryPath "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "FavoritesResolve" -PropertyType "Binary" -Value ([byte[]](0xFF))
ChangeRegistry -registryPath "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "FavoritesChanges" -PropertyType "DWORD" -Value 0
ChangeRegistry -registryPath "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "FavoritesVersion" -PropertyType "DWORD" -Value 1
Stop-Process -Name explorer -ErrorAction SilentlyContinue

Finally I use the InvokeVerb method to put back what I want:

$ShellApplication = New-Object -ComObject Shell.Application
$result=$ShellApplication.Namespace("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office").ParseName("Microsoft Outlook 2010.lnk").InvokeVerb("taskbarpin")

Re-imaging a machine, with SCCM 2012 fails with error 0x80070570

I have been working on building a new Windows 10 image. I was testing on a laptop and all of the sudden the OSD Task Sequence started failing, before anything even started!
I had only made a minor change to the TaskSequence, so I was pulling my hair out.

Error 0x80070570. 
Logs shows : threadtoresolveandexecutetasksequence failed 0x80070570.

If you are impatient like me, then you you power off the machine (press and hold the power button), and start over.
Well, that was the issue. Drive was marked as dirty (so many power offs throughout the day!) and a check disk needed to be run.

Hope that helps someone.

Quick PowerShell script to check DNS settings on all servers

I wanted to decommission some old Domain Controllers. I needed to make sure that other servers weren’t pointing to theses old DCs for DNS. I wrote this quick PowerShell script to loop through all servers and get their DNS search order.

$AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"}
ForEach ($Server in $AllServers){
$Result=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $Server.Name 
$output = new-object PSObject 
$output | add-member NoteProperty "ComputerName" $Server.Name
$output | add-member NoteProperty "DNSServerSearchOrder" $Result.DNSServerSearchOrder
$output
}

Hope that helps some one, or me when we moce to the next version of DCs.

Quick PowerShell script to “tail -f” dhcp logs

When I am working in Linux, I like to leave a log open with “tail -f”, so I can see the results of some test I am performing.

The other day I wanted to see when a new machine joined the network, so I could give it a static DHCP lease. Usually I connect to the DHCP server find the DHCP logs and open them in notepad. I finally wrote a quick script to “tail -f dhcp.log” in PowerShell.

 

function JBM-AD-GetDHCPLogs {
 PARAM($ServerName="dhcpServerName")
 $FileName="DhcpSrvLog-$(get-date -format ddd).log"
 $PATH="\\$ServerName\c$\Windows\System32\dhcp\$FileName"
 Get-Content $path –Wait
 }