Mick's IT Blogs

My blog is here to help solve issues I have encountered and solved, publish scripts I have written, and educate others in understanding areas that are not well covered.

Mick's IT Blogs

Information Technology Zone

25 July 2014

MSI Error 1325: is not a valid short file name

This error in my case was being caused because the MSI was being executed through SCCM. The MSI file had to be executed locally and not from a network source. It would install with no issues if you double-clicked on the MSI. It only happened when SCCM tried to install it. During my troubleshooting, I tried a few different alternatives:

  • I use a PowerShell script to install the package. I thought it could be causing the issue, so I created a new SCCM package that only executed the MSI with the following command line, but the error persisted: msiexec.exe /I iDocID_for_32bit_Office.msi /qb-
  • I created a GPO that installed the MSI

These options did not resolve the issue. I then decided that if the issue was because the MSI needs to execute locally, then why not use psexec? I created the following command line to incorporate into an SCCM program. It failed the first time I ran it. The second time was successful after I went back into the environment tab and ran it with user rights. Basically this executes the package on the local machine under the user profile of the logged on user but runs the installer with the SCCM admin account. This resolved my issue.


\\    <network share>\psexec.exe \\%computername% -accepteula -u <username> -p <password> cmd.exe /c "echo . | powershell.exe -executionpolicy bypass -file <network share>\install.ps1"

07 July 2014

SCCM: Adjust Screen Resolution during Build

Sometimes the screen resolution in a build does not set to the maximum. Resolution can be set with PowerShell, but the scripting requirements and complexity is too much, IMO. AutoIT offers an easy way to automate this process. I have written this script to do just that. There is documentation within the script. You will need to have the AutoIT compiler for this. Here is the link to download it.


 #Region ;**** Directives created by AutoIt3Wrapper_GUI ****  
 #AutoIt3Wrapper_Outfile=install.exe  
 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****  
 ; Open Screen Resolution  
 Run( "control desk.cpl" )  
 Sleep( 2000 )  
 ; Tab to Resolution  
 Send( "{TAB}" )  
 Sleep( 250 )  
 Send( "{TAB}" )  
 Sleep( 250 )  
 ; Open Resolution Drop Down  
 Send( "{Enter}" )  
 Sleep( 250 )  
 ; Move Resolution Up to max. You may need to add more up arrows.  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 Send( "{UP}" )  
 Sleep( 250 )  
 ; Accept resolution  
 Send( "{Enter}" )  
 Sleep( 250 )  
 ; Move to OK button  
 Send( "{TAB}" )  
 Sleep( 250 )  
 Send( "{TAB}" )  
 Sleep( 250 )  
 Send( "{TAB}" )  
 Sleep( 250 )  
 Send( "{TAB}" )  
 Sleep( 250 )  
 Send( "{TAB}" )  
 Sleep( 250 )  
 ; Apply New Resolution  
 Send( "{Enter}" )  
 Sleep( 5000 )  
 ; Accept New Resolution  
 Send( "k" )  
   

27 June 2014

PowerShell: SCCM Client Installer

Installing the SCCM client takes a few minutes. This script was written so that it will wait for the ccmsetup.exe to complete. I have encountered issues with the setup not completing before the system reboots during a build process. That is the reason I wrote this script. There are verifications in this script and it does write a log file. If you don't want the logs, just remove those parts of the script. This script was originally written for SCCM 2007, but it will work on 2012 too. You can download it from here.


 <#  
 .NAME  
   Mick Pletcher  
 .DATE  
   13 June 2014  
 .SYNOPSIS  
   SCCM 2007  
 .DESCRIPTION  
   <A detailed description of the script>  
 .PARAMETER <paramName>  
   <Description of script parameter>  
 .EXAMPLE  
   <An example of using the script>  
 #>  
   
 #Declare Global Memory  
 Set-Variable -Name BuildLog -Scope Global -Force  
 Set-Variable -Name Errors -Value $null -Scope Global -Force  
 Set-Variable -Name LogFile -Scope Global -Force  
 Set-Variable -Name RelativePath -Scope Global -Force  
 Set-Variable -Name Sequence -Scope Global -Force  
 Set-Variable -Name Title -Scope Global -Force  
   
 Function DeclareGlobalVariables {  
      $Global:BuildLog = $Env:windir+"\Logs\BuildLogs\Build.log"  
      $Global:LogFile = $Env:windir+"\Logs\BuildLogs\SCCM2007Client.log"  
      $Global:Sequence = "01"  
      $Global:Title = "SCCM 2007 Client"  
 }  
   
 Function ConsoleTitle ($Title){  
      $host.ui.RawUI.WindowTitle = $Title  
 }  
   
 Function GetRelativePath {   
      $Global:RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"   
 }  
   
 Function UninstallMSI ($ProgName,$GUID) {  
      $EXE = $Env:windir+"\system32\msiexec.exe"  
      $Switches = [char]32+"/qb- /norestart"  
      $Parameters = "/x "+$GUID+$Switches  
      $Output = "Uninstall"+$ProgName+"....."  
      Write-Host "Uninstall"$ProgName"....." -NoNewline  
      $ErrCode = (Start-Process -FilePath $EXE -ArgumentList $Parameters -Wait -Passthru).ExitCode  
      If (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {  
           $Output = $Output+"Success"  
           Write-Host "Success" -ForegroundColor Yellow  
      } elseIf ($ErrCode -eq 1605) {  
           $Output = $Output+"Not Present"  
           Write-Host "Not Present" -ForegroundColor Green  
      } else {  
           $Output = $Output+"Failed with error code "+$ErrCode  
           Write-Host "Failed with error code "$ErrCode -ForegroundColor Red  
           $Global:Errors++  
      }  
      Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force  
 }  
   
 Function InstallMSI ($ProgName,$MSI,$Switches) {  
      $EXE = $Env:windir+"\system32\msiexec.exe"  
      $Parameters = "/i "+[char]34+$MSI+[char]34+[char]32+$Switches  
      $Output = "Install"+$ProgName+"....."  
      Write-Host "Install"$ProgName"....." -NoNewline  
      $ErrCode = (Start-Process -FilePath $EXE -ArgumentList $Parameters -Wait -Passthru).ExitCode  
      If (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {  
           $Output = $Output+"Success"  
           Write-Host "Success" -ForegroundColor Yellow  
      } else {  
           $Output = $Output+"Failed with error code "+$ErrCode  
           Write-Host "Failed with error code "$ErrCode -ForegroundColor Red  
           $Global:Errors++  
      }  
      Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force  
 }  
   
 Function InstallEXE ($ProgName,$EXE,$Switches){  
      $Output = "Install "+$ProgName+"....."  
      Write-Host "Install "$ProgName"....." -NoNewline  
      $ErrCode = (Start-Process -FilePath $EXE -ArgumentList $Switches -Wait -Passthru).ExitCode  
      If (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {  
           $Output = $Output+"Success"  
           Write-Host "Success" -ForegroundColor Yellow  
      } else {  
           $Output = $Output+"Failed with error code "+$ErrCode  
           Write-Host "Failed with error code "$ErrCode -ForegroundColor Red  
           $Global:Errors++  
      }  
      Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force  
 }  
   
 Function InstallMSP ($ProgName,$MSP,$Switches) {  
      $EXE = $Env:windir+"\system32\msiexec.exe"  
      $Parameters = "/p "+[char]34+$MSP+[char]34+[char]32+$Switches  
      $Output = "Install"+$ProgName+"....."  
      Write-Host "Install"$ProgName"....." -NoNewline  
      $ErrCode = (Start-Process -FilePath $EXE -ArgumentList $Parameters -Wait -Passthru).ExitCode  
      If (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {  
           $Output = $Output+"Success"  
           Write-Host "Success" -ForegroundColor Yellow  
      } else {  
           $Output = $Output+"Failed with error code "+$ErrCode  
           Write-Host "Failed with error code "$ErrCode -ForegroundColor Red  
           $Global:Errors++  
      }  
      Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force  
 }  
   
 Function WaitForProcessEnd ($Process) {  
      $Proc = Get-Process $Process -ErrorAction SilentlyContinue  
      $Output = "Waiting for"+$Process+"to complete....."  
      Write-Host "Waiting for"$Process" to complete....." -NoNewline  
      If ($Proc -ne $null) {  
           Do {  
                Start-Sleep -Seconds 5  
                $Proc = Get-Process $Process -ErrorAction SilentlyContinue  
           } While ($Proc -ne $null)  
           $Output = $Output+"Completed"  
           Write-Host "Completed" -ForegroundColor Yellow  
      } else {  
           $Output = $Output+"Already Completed"  
           Write-Host "Already Completed" -ForegroundColor Yellow  
      }  
      Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force  
 }  
   
 Function ProcessLogFile {  
      If ((Test-Path $Env:windir"\Logs") -eq $false) {  
           New-Item -ItemType Directory -Path $Env:windir"\Logs"  
      }  
      If ((Test-Path $Env:windir"\Logs\ApplicationLogs") -eq $false) {  
           New-Item -ItemType Directory -Path $Env:windir"\Logs\ApplicationLogs"  
      }  
      If ((Test-Path $Env:windir"Logs\BuildLogs") -eq $false) {  
           New-Item -ItemType Directory -Path $Env:windir"\Logs\BuildLogs"  
      }  
      If ($Global:Errors -eq $null) {  
           If (Test-Path $Global:LogFile) {  
                Remove-Item $Global:LogFile -Force  
           }  
           $File1 = $Global:LogFile.Split(".")  
           $Filename1 = $File1[0]+"_ERROR"+"."+$File1[1]  
           If (Test-Path $Filename1) {  
                Remove-Item $Filename1 -Force  
           }  
           $Global:Errors = 0  
      } elseIf ($Global:Errors -ne 0) {  
           If (Test-Path $Global:LogFile) {  
                $Global:LogFile.ToString()  
                $File1 = $Global:LogFile.Split(".")  
                $Filename1 = $File1[0]+"_ERROR"+"."+$File1[1]  
                Rename-Item $Global:LogFile -NewName $Filename1 -Force  
           }  
      } else {  
           $LogTitle = $Global:Sequence+" - "+$Global:Title  
           Out-File -FilePath $Global:BuildLog -InputObject $LogTitle -Append -Force  
      }  
 }  
   
 cls  
 DeclareGlobalVariables  
 GetRelativePath  
 ConsoleTitle $Global:Title  
 ProcessLogFile  
 UninstallMSI "Microsoft SCCM 2007 Client" $Global:RelativePath"i386\client.msi"  
 InstallMSI "Microsoft XML 6" $Global:RelativePath"i386\msxml6.msi" "/qb- /norestart"  
 InstallEXE "Microsoft SCCM 2007" $Global:RelativePath"ccmsetup.exe" "SMSSITECODE=ENT SMSCACHESIZE=5120"  
 WaitForProcessEnd "CCMSETUP"  
 InstallMSP "KB977203" $Global:RelativePath"i386\sccm2007ac-sp2-kb977203-x86.msp" "/qb- /norestart"  
 InstallMSP "KB2659258" $Global:RelativePath"i386\sccm2007ac-sp2-kb2659258-x86-enu.msp" "/qb- /norestart"  
 ProcessLogFile  
 Start-Sleep -Seconds 5  
   

PowerShell: Pinning Shortcuts to the Taskbar and Start Menu

There are already scripts out there that will do this, but I have taken it a little further. I have added checking to make sure the application is installed first so that the script does not error out. I have also added on-screen display to show if it was successful or not. I originally started off of the answer here and then expanded. One weird thing I encountered while writing this was that it treated excel 2010 differently than all other shortcuts. That is why you will see the extra three lines of code specifically for excel. You can download the script from here.


 <#  
 .NAME  
   Mick Pletcher  
 .DATE  
   11 May 2014  
 .SYNOPSIS  
   Taskbar Shortcuts  
 .DESCRIPTION  
   Create taskbar shortcuts  
 .PARAMETER <paramName>  
   <Description of script parameter>  
 .EXAMPLE  
   <An example of using the script>  
 #>  
   
 #Declare Global Memory  
 Set-Variable -Name Architecture -Scope Global -Force  
 Set-Variable -Name RelativePath -Scope Global -Force  
 Set-Variable -Name Title -Value "Application Shortcuts" -Scope Global -Force  
   
 Function ConsoleTitle ($Title){  
      $host.ui.RawUI.WindowTitle = $Title  
 }  
   
 Function GetRelativePath {   
      $Global:RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"   
 }  
   
 Function GetArchitecture {  
      $Global:Architecture = Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture  
      $Global:Architecture = $Global:Architecture.OSArchitecture  
      #Returns 32-bit or 64-bit  
 }  
   
 Function PinToStartMenu ($AppName,$PinnedApp,$App) {  
      Write-Host "Pin"$AppName" on Start Menu....." -NoNewline  
      If ((Test-Path $App) -eq $true) {  
           If ((Test-Path $PinnedApp) -eq $false) {  
                $sa = new-object -c shell.application  
                $AppSplit = $App.split("\")  
                $AppSplitCount = $AppSplit.Count  
                $Filename = $AppSplit[$AppSplitCount-1]  
                For ($i=0; $i -lt $AppSplitCount-1) {  
                     $DirectoryPath = $DirectoryPath+$AppSplit[$i]  
                     If ($i -ne $AppSplitCount-2) {  
                          $DirectoryPath = $DirectoryPath+"\"  
                     }  
                     $i++  
                }  
                $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
                $pn.invokeverb('startpin')  
                If ((Test-Path $PinnedApp) -eq $true) {  
                     Write-Host "Success" -ForegroundColor Yellow  
                } else {  
                     Write-Host "Failed " -ForegroundColor Red  
                }  
           } else {  
                Write-Host "Already Present" -ForegroundColor Yellow  
           }  
      } else {  
           Write-Host "Application not installed" -ForegroundColor Green  
      }  
 }  
   
 Function PinToTaskbar ($AppName,$PinnedApp,$App) {  
      Write-Host "Pin"$AppName" to Taskbar....." -NoNewline  
      If ((Test-Path $App) -eq $true) {  
           If ((Test-Path $PinnedApp) -eq $false) {  
                $sa = new-object -c shell.application  
                $AppSplit = $App.split("\")  
                $AppSplitCount = $AppSplit.Count  
                $Filename = $AppSplit[$AppSplitCount-1]  
                For ($i=0; $i -lt $AppSplitCount-1) {  
                     $DirectoryPath = $DirectoryPath+$AppSplit[$i]  
                     If ($i -ne $AppSplitCount-2) {  
                          $DirectoryPath = $DirectoryPath+"\"  
                     }  
                     $i++  
                }  
                $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
                $pn.invokeverb('taskbarpin')  
                If ((Test-Path $PinnedApp) -eq $true) {  
                     Write-Host "Success" -ForegroundColor Yellow  
                } else {  
                     Write-Host "Failed " -ForegroundColor Red  
                }  
           } else {  
                Write-Host "Already Present" -ForegroundColor Yellow  
           }  
      } else {  
           Write-Host "Application not installed" -ForegroundColor Green  
      }  
 }  
   
 Function UnpinFromStartMenu ($AppName,$PinnedApp,$App) {  
      Write-Host "Unpin"$AppName" from Start Menu....." -NoNewline  
      If ((Test-Path $PinnedApp) -eq $true) {  
           $sa = new-object -c shell.application  
           $AppSplit = $App.split("\")  
           $AppSplitCount = $AppSplit.Count  
           $Filename = $AppSplit[$AppSplitCount-1]  
           For ($i=0; $i -lt $AppSplitCount-1) {  
                $DirectoryPath = $DirectoryPath+$AppSplit[$i]  
                If ($i -ne $AppSplitCount-2) {  
                     $DirectoryPath = $DirectoryPath+"\"  
                }  
                $i++  
           }  
           $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
           $pn.invokeverb('startunpin')  
           If ((Test-Path $PinnedApp) -eq $false) {  
                Write-Host "Success" -ForegroundColor Yellow  
           } else {  
                Write-Host "Failed " -ForegroundColor Red  
           }  
      } else {  
           Write-Host "Already Removed" -ForegroundColor Yellow  
      }  
 }  
   
 Function UnpinFromTaskbar ($AppName,$PinnedApp,$App) {  
      Write-Host "Unpin"$AppName" from Taskbar....." -NoNewline  
      If ((Test-Path $PinnedApp) -eq $true) {  
           $AppSplit = $App.split("\")  
           $AppSplitCount = $AppSplit.Count  
           $Filename = $AppSplit[$AppSplitCount-1]  
           $DirectoryPath = $App.Trim($Filename)  
           $DirectoryPath = $DirectoryPath.Trim("\")  
           If ($Filename -eq "EXCEL.EXE") {  
                $DirectoryPath = "c"+$DirectoryPath  
           }  
           $sa = new-object -c shell.application  
           $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
           $pn.invokeverb('taskbarunpin')  
           If ((Test-Path $PinnedApp) -eq $false) {  
                Write-Host "Success" -ForegroundColor Yellow  
           } else {  
                Write-Host "Failed " -ForegroundColor Red  
           }  
      } else {  
           Write-Host "Already Removed" -ForegroundColor Yellow  
      }  
 }  
   
 cls  
 GetRelativePath  
 ConsoleTitle $Global:Title  
 GetArchitecture  
 If ($Global:Architecture -eq "32-bit") {  
      UnpinFromStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
      UnpinFromStartMenu "eDocs DM" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Open Text eDocs Email Marker.lnk" "C:\Program Files\Open Text\Email Filing\DMMarkEmail.exe"  
      PinToStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      PinToStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      PinToStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
      UnpinFromTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
      PinToTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      PinToTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      PinToTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
 } else {  
      UnpinFromStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
      PinToStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      PinToStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      PinToStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
      UnpinFromTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
      PinToTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      PinToTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      PinToTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
 }  
 

29 May 2014

PowerShell: Enable Wake-On-LAN

This script will enable WOL and test to make sure it has been set. It will return whether it was a success or failure both to a log file and the screen. This script was written to also be incorporated with my new build logging process that I am getting ready to release soon. If you do not want this, just delete the buildlog and sequence variables out, along with their use in the ProcessLogFile function.




 <#  
 .SYNOPSIS  
   Wake-On-LAN  
 .DESCRIPTION  
   Enable Wake-On-LAN  
 .PARAMETER <paramName>  
   <Description of script parameter>  
 .EXAMPLE  
   <An example of using the script>  
 #>  
 #Declare Global Memory  
 Set-Variable -Name AppLog -Scope Global -Force  
 Set-Variable -Name BuildLog -Scope Global -Force  
 Set-Variable -Name Errors -Value $null -Scope Global -Force  
 Set-Variable -Name LogFile -Scope Global -Force  
 Set-Variable -Name RelativePath -Scope Global -Force  
 Set-Variable -Name Sequence -Scope Global -Force  
 Set-Variable -Name Title -Scope Global -Force  
 Function ConsoleTitle ($Title){  
      $host.ui.RawUI.WindowTitle = $Title  
 }  
 Function DeclareGlobalVariables {  
      $Global:AppLog = "/lvx "+$Env:windir + "\Logs\ApplicationLogs\WakeOnLAN.log"  
      $Global:BuildLog = $Env:windir + "\Logs\BuildLogs\Build.log"  
      $Global:LogFile = $Env:windir + "\Logs\BuildLogs\WakeOnLAN.log"  
      $Global:Sequence = "08"  
      $Global:Title = "Wake On LAN"  
 }  
 Function GetRelativePath {   
      $Global:RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"   
 }  
 Function EnableWOL {  
      # Get all physical ethernet adaptors  
      $nics = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' `  
      AND PhysicalAdapter = 'true' `  
      AND NOT Description LIKE '%Centrino%' `  
      AND NOT Description LIKE '%wireless%' `  
      AND NOT Description LIKE '%virtual%' `  
      AND NOT Description LIKE '%WiFi%' `  
      AND NOT Description LIKE '%Bluetooth%'"  
      foreach ($nic in $nics) {  
           $nicName = $nic.Name  
           $Output = "NIC:"+$nicName+[char]10  
           Write-Host "NIC:"$nicName  
           $Output = $Output + "Allow the computer to turn off this device....."  
           Write-Host "Allow the computer to turn off this device....." -NoNewline  
           $nicPower = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }  
           If ($nicPower.Enable -ne $True) {  
                $nicPower.Enable = $True  
                $Temp = $nicPower.psbase.Put()  
           }  
           If ($nicPower.Enable -eq $True) {  
                $Output = $Output + "Enabled"  
                Write-Host "Enabled" -ForegroundColor Yellow  
           } else {  
                $Output = $Output + "Failed"  
                Write-Host "Failed" -ForegroundColor Red  
           }  
           $Output = $Output + [char]10  
           $Output = $Output + "Allow this device to wake the computer....."  
           Write-Host "Allow this device to wake the computer....." -NoNewline  
           $nicPowerWake = Get-WmiObject MSPower_DeviceWakeEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }  
           If ($nicPowerWake.Enable -ne $True) {  
                $nicPowerWake.Enable = $True  
                $Temp = $nicPowerWake.psbase.Put()  
           }  
           If ($nicPowerWake.Enable -eq $True) {  
                $Output = $Output + "Enabled"  
                Write-Host "Enabled" -ForegroundColor Yellow  
           } else {  
                $Output = $Output + "Failed"  
                Write-Host "Failed" -ForegroundColor Red  
           }  
           $Output = $Output + [char]10  
           $Output = $Output + "Only allow a magic packet to wake the computer....."  
           Write-Host "Only allow a magic packet to wake the computer....." -NoNewline  
           $nicMagicPacket = Get-WmiObject MSNdis_DeviceWakeOnMagicPacketOnly -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }  
           If ($nicMagicPacket.EnableWakeOnMagicPacketOnly -ne $True) {  
                $nicMagicPacket.EnableWakeOnMagicPacketOnly = $True  
                $Temp = $nicMagicPacket.psbase.Put()  
           }  
           If ($nicMagicPacket.EnableWakeOnMagicPacketOnly -eq $True) {  
                $Output = $Output + "Enabled"  
                Write-Host "Enabled" -ForegroundColor Yellow  
           } else {  
                $Output = $Output + "Failed"  
                Write-Host "Failed" -ForegroundColor Red  
           }  
      }  
      Out-File -FilePath $Global:LogFile -InputObject $Output -Append -Force  
 }  
 Function ProcessLogFile {  
      If ((Test-Path $Env:windir"\Logs") -eq $false) {  
           New-Item -ItemType Directory -Path $Env:windir"\Logs"  
      }  
      If ((Test-Path $Env:windir"\Logs\ApplicationLogs") -eq $false) {  
           New-Item -ItemType Directory -Path $Env:windir"\Logs\ApplicationLogs"  
      }  
      If ((Test-Path $Env:windir"\Logs\BuildLogs") -eq $false) {  
           New-Item -ItemType Directory -Path $Env:windir"\Logs\BuildLogs"  
      }  
      If ($Global:Errors -eq $null) {  
           If (Test-Path $Global:LogFile) {  
                Remove-Item $Global:LogFile -Force  
           }  
           $File1 = $Global:LogFile.Split(".")  
           $Filename1 = $File1[0]+"_ERROR"+"."+$File1[1]  
           If (Test-Path $Filename1) {  
                Remove-Item $Filename1 -Force  
           }  
           $Global:Errors = 0  
      } elseIf ($Global:Errors -ne 0) {  
           If (Test-Path $Global:LogFile) {  
                $Global:LogFile.ToString()  
                $File1 = $Global:LogFile.Split(".")  
                $Filename1 = $File1[0]+"_ERROR"+"."+$File1[1]  
                Rename-Item $Global:LogFile -NewName $Filename1 -Force  
           }  
      } else {  
           $LogTitle = $Global:Sequence + " - "+$Global:Title  
           Out-File -FilePath $Global:BuildLog -InputObject $LogTitle -Append -Force  
      }  
 }  
 Function ExitPowerShell {  
      If ($Global:Errors -ne $null) {  
           Exit 1  
      }  
 }  
 cls  
 GetRelativePath  
 DeclareGlobalVariables  
 ConsoleTitle $Global:Title  
 ProcessLogFile  
 EnableWOL  
 ProcessLogFile  
 ExitPowerShell  
 Start-Sleep -Seconds 10  

22 May 2014

Executing Command Line on Remote Systems

I have been a huge fan of PsExec ever since I became and SCCM Administrator. The problem with PsExec is that it transmits credentials in clear text. There is a great alternative to this and it is PAExec. It is freeware and can be redistributed. It has all of the same functionality as PsExec with a few additional minor features. You can get the software at PowerAdmin.

02 May 2014

PowerShell: Enable or Disable Internet Explorer Active X Components

This script will enable or disable Internet Explorer Active X components. All you have to do is pass the user friendly name of the component, component's GUID, and the flag. The app will verify if the change actually takes place and returns a success or failure status.

You can download this from here.


<#
.SYNOPSIS
   Enable/Disable IE Active X Components
.DESCRIPTION
   
.PARAMETER <paramName>
   <Description of script parameter>
.EXAMPLE
   EnableIEActiveXControl "Application Name" "GUID" "Value"
   EnableIEActiveXControl "Flash for IE" "{D27CDB6E-AE6D-11CF-96B8-444553540000}" "0x00000000"
#>

#Declare Global Memory
Set-Variable -Name Errors -Value $null -Scope Global -Force
Set-Variable -Name LogFile -Value "c:\windows\waller\Logs\BuildLogs\AdobeFlashPlayer.log" -Scope Global -Force
Set-Variable -Name RelativePath -Scope Global -Force

Function ConsoleTitle ($Title){
    $host.ui.RawUI.WindowTitle = $Title
}

Function GetRelativePath { 
    $Global:RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\" 
}

Function DisableIEActiveXControl ($AppName,$GUID,$Flag) {
    $Key = "HKLM:\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\"+$GUID
    If ((Test-Path $Key) -eq $true) {
        Write-Host $AppName"....." -NoNewline
        Set-ItemProperty -Path $Key -Name "Compatibility Flags" -Value $Flag -Force
        $Var = Get-ItemProperty -Path $Key -Name "Compatibility Flags"
        If ($Var."Compatibility Flags" -eq 1024) {
            Write-Host "Disabled" -ForegroundColor Yellow
        } else {
            Write-Host "Enabled" -ForegroundColor Red
        }
    }
}

Function EnableIEActiveXControl ($AppName,$GUID,$Flag) {
    $Key = "HKLM:\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\"+$GUID
    If ((Test-Path $Key) -eq $true) {
        Write-Host $AppName"....." -NoNewline
        Set-ItemProperty -Path $Key -Name "Compatibility Flags" -Value $Flag -Force
        $Var = Get-ItemProperty -Path $Key -Name "Compatibility Flags"
        If ($Var."Compatibility Flags" -eq 0) {
            Write-Host "Enabled" -ForegroundColor Yellow
        } else {
            Write-Host "Disabled" -ForegroundColor Red
        }
    }
}

cls
#DisableIEActiveXControl "Flash for IE" "{D27CDB6E-AE6D-11CF-96B8-444553540000}" "0x00000400"
EnableIEActiveXControl "Flash for IE" "{D27CDB6E-AE6D-11CF-96B8-444553540000}" "0x00000000"
Start-Sleep -Seconds 5