This is how you update a record in a database using PowerShell. I’m using this to modify the OS field, which is sometimes delayed due to slow inventory scans.
Note, where it says “The_”, I recommend using variables in your scripting.
Set-Location SQLSERVER:\SQL\The_SQL_Server_Name\The_SQL_Instance
Invoke-Sqlcmd -Query "UPDATE dbo.vSMS_R_System SET Operating_System_Name_and0 = 'Microsoft Windows NT Workstation 10.0' WHERE Name0='The_Computer_Name'" -Database "The_SCCM_DB_Name"
If you’re like me, you like the simplicity of certain apps and functions. When previewing photos, my favorite app was the Windows Photo Viewer. Well, if you notice, in Windows 10 it has gone away; you can no longer associate image types to Photo Viewer. To bring back the availability of Photo Viewer, just copy and paste the following into notepad, name photoviewer.reg, and double-click it. When selecting one of your images, right-click, and this will add the option to Open With > Choose Another App > More Apps….scroll down to the bottom. This will also add the option to the Default apps area in Settings.
Save as photoviewer.reg, double-click
Windows Registry Editor Version 5.00
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.jpg] @=”PhotoViewer.FileAssoc.Tiff”
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.jpeg] @=”PhotoViewer.FileAssoc.Tiff”
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.gif] @=”PhotoViewer.FileAssoc.Tiff”
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.png] @=”PhotoViewer.FileAssoc.Tiff”
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.bmp] @=”PhotoViewer.FileAssoc.Tiff”
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.tiff] @=”PhotoViewer.FileAssoc.Tiff”
; Change Extension’s File Type [HKEY_CURRENT_USER\Software\Classes\.ico] @=”PhotoViewer.FileAssoc.Tiff”
After upgrading to Windows 10, if you’re using some kind of DVI/Display port adapter for dual screen setup, you may notice that one of the monitors have a corrupted or black screen, or only showing on half of the monitor. This is due to how W10 communicates with the port. At first, you may think it’s the display driver itself; it is not. Then, you may think the OS needs to be repaired in some way; it doesn’t.
Screenshot of Dual Monitor Setup
The driver error
Specifically, the 1709 Fall Creators update has compatibility issues with older display ports. So, some adapter drivers (from the original vendor or built into MS) will not work.
The solution? To install the j5create DVI adapter driver. It does not matter which adapter you’re using, the j5create installs the necessary W10 component, which in turn allows the regular video driver to communicate with the display port (Microsoft left out this piece in 1709). Go figure.
Function Set-WindowPosition {
<# .SYNOPSIS Sets the window size (height,width) and coordinates (x,y) of a process window. .DESCRIPTION Sets the window size (height,width) and coordinates (x,y) of a process window. .PARAMETER ProcessName Name of the process to determine the window characteristics .PARAMETER X Set the position of the window in pixels from the top. .PARAMETER Y Set the position of the window in pixels from the left. .PARAMETER Width Set the width of the window. .PARAMETER Height Set the height of the window. .PARAMETER Passthru Display the output object of the window. .OUTPUT System.Automation.WindowInfo .EXAMPLE Get-Process powershell | Set-Window -X 2040 -Y 142 -Passthru ProcessName Size TopLeft BottomRight ----------- ---- ------- ----------- powershell 1262,642 2040,142 3302,784 Description ----------- Set the coordinates on the window for the process PowerShell.exe #>
[OutputType('System.Automation.WindowInfo')]
[cmdletbinding()]
Param (
[parameter(ValueFromPipelineByPropertyName=$True)]
$ProcessName,
[int]$X,
[int]$Y,
[int]$Width,
[int]$Height,
[switch]$Passthru
)
Begin {
Try{
[void][Window]
} Catch {
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Window {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("User32.dll")]
public extern static bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
}
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
"@
}
}
Process {
$Rectangle = New-Object RECT
$Handle = (Get-Process -Name $ProcessName).MainWindowHandle
$Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
If (-NOT $PSBoundParameters.ContainsKey('Width')) {
$Width = $Rectangle.Right - $Rectangle.Left
}
If (-NOT $PSBoundParameters.ContainsKey('Height')) {
$Height = $Rectangle.Bottom - $Rectangle.Top
}
If ($Return) {
$Return = [Window]::MoveWindow($Handle, $x, $y, $Width, $Height,$True)
}
If ($PSBoundParameters.ContainsKey('Passthru')) {
$Rectangle = New-Object RECT
$Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
If ($Return) {
$Height = $Rectangle.Bottom - $Rectangle.Top
$Width = $Rectangle.Right - $Rectangle.Left
$Size = New-Object System.Management.Automation.Host.Size -ArgumentList $Width, $Height
$TopLeft = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Left, $Rectangle.Top
$BottomRight = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Right, $Rectangle.Bottom
If ($Rectangle.Top -lt 0 -AND $Rectangle.LEft -lt 0) {
Write-Warning "Window is minimized! Coordinates will not be accurate."
}
$Object = [pscustomobject]@{
ProcessName = $ProcessName
Size = $Size
TopLeft = $TopLeft
BottomRight = $BottomRight
}
$Object.PSTypeNames.insert(0,'System.Automation.WindowInfo')
$Object
}
}
}
}
powershell (Add-Type ‘[DllImport(\”user32.dll\”)]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);’ -Name a -Pas)::SendMessage(-1,0×0112,0xF170,2)
#requires -Version 3
<
.SYNOPSIS
The RemoveAppxPackage command will remove Windows Store Appx packages.
.DESCRIPTION
This script can help you to remove several Windows Store Apps at one time.
.EXAMPLE
PS C:>; C:\Script\RemoveWindowsStoreApp.ps1
ID App name
1 Microsoft.Media.PlayReadyClient.2
2 Microsoft.Media.PlayReadyClient.2
3 CheckPoint.VPN
4 f5.vpn.client
5 FileManager
6 JuniperNetworks.JunosPulseVpn
7 Microsoft.MoCamera
8 SonicWALL.MobileConnect
9 windows.immersivecontrolpanel
10 winstore
11 Microsoft.BingSports
12 Microsoft.BingTravel
13 Microsoft.SkypeApp
14 Microsoft.BingFinance
15 Microsoft.HelpAndTips
16 Microsoft.BingFoodAndDrink
17 Microsoft.BingHealthAndFitness
18 Microsoft.BingNews
19 microsoft.windowscommunicationsapps
20 Microsoft.WindowsSoundRecorder
21 Microsoft.WindowsScan
22 Microsoft.ZuneMusic
23 Microsoft.VCLibs.120.00
24 Microsoft.WindowsAlarms
25 Microsoft.WinJS.2.0
26 Microsoft.WindowsCalculator
27 Microsoft.BingWeather
28 Microsoft.Reader
29 Microsoft.ZuneVideo
30 Microsoft.WindowsReadingList
31 Microsoft.BingMaps
32 Microsoft.XboxLIVEGames
33 Microsoft.VCLibs.120.00
Which Apps do you want to remove?
Input their IDs and seperate IDs by comma: 28
This example shows how to list all Windows Store apps, and remove the apps specified by user.
.LINK
Windows PowerShell Advanced Function
http://technet.microsoft.com/en-us/library/dd315326.aspx
.LINK
Get-AppxPackage
http://technet.microsoft.com/en-us/library/hh856044.aspx
.LINK
Remove-AppxPackage
http://technet.microsoft.com/en-us/library/hh856038.aspx
>
Import-LocalizedData -BindingVariable Messages
Function PSCustomErrorRecord
{
#This function is used to create a PowerShell ErrorRecord
Param
(
[Parameter(Mandatory=$true,Position=1)][String]$ExceptionString,
[Parameter(Mandatory=$true,Position=2)][String]$ErrorID,
[Parameter(Mandatory=$true,Position=3)][System.Management.Automation.ErrorCategory]$ErrorCategory,
[Parameter(Mandatory=$true,Position=4)][PSObject]$TargetObject
)
Process
{
$exception = New-Object System.Management.Automation.RuntimeException($ExceptionString)
$customError = New-Object System.Management.Automation.ErrorRecord($exception,$ErrorID,$ErrorCategory,$TargetObject)
return $customError
}
}
Function RemoveAppxPackage
{
$index=1
$apps=Get-AppxPackage
#return entire listing of applications
Write-Host "ID`t App name"
foreach ($app in $apps)
{
Write-Host " $index`t $($app.name)"
$index++
}
Do
{
$IDs=Read-Host -Prompt "Which Apps do you want to remove? `nInput their IDs and seperate IDs by comma"
}
While($IDs -eq "")
#check whether input values are correct
try
{
[int[]]$IDs=$IDs -split ","
}
catch
{
$errorMsg = $Messages.IncorrectInput
$errorMsg = $errorMsg -replace "Placeholder01",$IDs
$customError = PSCustomErrorRecord `
-ExceptionString $errorMsg `
-ErrorCategory NotSpecified -ErrorID 1 -TargetObject $pscmdlet
$pscmdlet.WriteError($customError)
return
}
foreach ($ID in $IDs)
{
#check id is in the range
if ($ID -ge 1 -and $ID -le $apps.count)
{
$ID--
#Remove each app
$AppName=$apps[$ID].name
Remove-AppxPackage -Package $apps[$ID] -ErrorAction SilentlyContinue
if (-not(Get-AppxPackage -Name $AppName))
{
Write-host "$AppName has been removed successfully"
}
else
{
Write-Warning "Remove '$AppName' failed! This app is part of Windows and cannot be uninstalled on a per-user basis."
}
}
else
{
$errorMsg = $Messages.WrongID
$errorMsg = $errorMsg -replace "Placeholder01",$ID
$customError = PSCustomErrorRecord `
-ExceptionString $errorMsg `
-ErrorCategory NotSpecified -ErrorID 1 -TargetObject $pscmdlet
$pscmdlet.WriteError($customError)
}
}
}
RemoveAppxPackage
To disable application load on startup for all users, add a value named
AppAutoStartDefaultVal with value 0 to the following registry location
HKLM\SOFTWARE\Intel\PIcon\Setting
To enable application load in ”disabled state” add a value named
AutoStartInDisabled with value 1 to the following registry location
HKLM\SOFTWARE\Intel\PIcon\Setting