-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-NVAPI.ps1
206 lines (163 loc) · 8.01 KB
/
Get-NVAPI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<#
.Name
Get-NVAPI
.Version
0.1
.SYNOPSIS
Example/test script for using the .NET NvAPIWrapper for managing NVidia GPUs
.DESCRIPTION
.Requirements
- Powershell v3.0 or higher
.EXAMPLE
\Get-NVAPI.ps1
.OUTPUTS
System.Management.Automation.PSObject
.Credits
https://github.com/falahati/NvAPIWrapper
.NOTES
Author: EZTechhelp
Site : https://www.eztechhelp.com
#>
#############################################################################
#region Configurable Script Parameters
#############################################################################
#----------------------------------------------
#region Global Variables
#----------------------------------------------
$Preferred_GPU_Value = 'id,2.0:220610DE,00000100,GF - (368,2,161,10240) @ (0)'
#----------------------------------------------
#endregion Global Variables
#----------------------------------------------
#############################################################################
#endregion Configurable Script Parameters
#############################################################################
#############################################################################
#region Execution and Output
#############################################################################
try
{
#Load the NVAPIWrapper.DLL
$null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\Assembly\NvAPIWrapper.dll")
#Get Primary Display Device
$PrimaryDisplayDevice = [NvAPIWrapper.Display.DisplayDevice]::GetGDIPrimaryDisplayDevice()
write-host "#### Primary Display Device ####" -ForegroundColor yellow
write-host "$($PrimaryDisplayDevice | out-string)" -ForegroundColor Cyan
}
catch
{
write-output "[ERROR] An exception occurred loading assemblies $_"
}
#----------------------------------------------
#region Retrieving Current Settings for Global Profile
#----------------------------------------------
try
{
#Load a new Driver Settings Session
$DriverSettingsSession = [NvAPIWrapper.DRS.DriverSettingsSession]::CreateAndLoad()
write-host "#### Driver Settings Session ####" -ForegroundColor yellow
write-host "$($DriverSettingsSession | out-string)" -ForegroundColor Cyan
#Display Current Global Profile and Settings
write-host "#### Current Global Profile and Settings ####" -ForegroundColor yellow
write-host "$($DriverSettingsSession.CurrentGlobalProfile | out-string)" -ForegroundColor Cyan
write-host "$($DriverSettingsSession.CurrentGlobalProfile.Settings | out-string)" -ForegroundColor Cyan
}
catch
{
write-output "[ERROR] An exception occurred getting Global Profile settings $_"
}
#----------------------------------------------
#endregion Retrieving Current Settings for Global Profile
#----------------------------------------------
#----------------------------------------------
#region Example for changing Preferred OpenGL GPU from Autoselect to specific GPU
#----------------------------------------------
function Set-PreferredGPU{
<#
.Example
Set-PreferredGPU -Preferred_GPU $Preferred_GPU_Value
#>
param (
[string]$Preferred_GPU
)
try
{
#Lets find what its currently set to
$DriverSettingsSession = [NvAPIWrapper.DRS.DriverSettingsSession]::CreateAndLoad()
$Preferred_OpenGL_GPU = $DriverSettingsSession.CurrentGlobalProfile.Settings | where {$_.SettingInfo.Name -eq 'Preferred OpenGL GPU'}
write-host "#### Current Preferred OpenGL GPU Value ####" -ForegroundColor Yellow
write-host "$($Preferred_OpenGL_GPU.CurrentValue | out-string)"
#Lets find what available setting values are
write-host "#### Available setting values for Preferred OpenGL GPU ####" -ForegroundColor Yellow
write-host "$($Preferred_OpenGL_GPU.SettingInfo.AvailableValues | out-string)"
#Lets get the value of the GPU we want (currently dont know how to know which setting is which GPU so using a reference machine with same hardware can help find value you want)
$New_Preferred_OpenGL_GPU_Value = $Preferred_OpenGL_GPU.SettingInfo.AvailableValues | where {$_ -eq $Preferred_GPU_Value}
#Now we can set the new value for Preferred OpenGL GPU. We will need the Setting ID, Setting type and new value
write-host ">>>> Setting new value to $New_Preferred_OpenGL_GPU_Value" -ForegroundColor Cyan
$DriverSettingsSession.CurrentGlobalProfile.SetSetting($Preferred_OpenGL_GPU.SettingId,$Preferred_OpenGL_GPU.SettingType,$New_Preferred_OpenGL_GPU_Value)
#Now lets save the profile
write-host ">>>> Saving Profile" -ForegroundColor Cyan
$DriverSettingsSession.Save()
#Now lets check the new value was set
$DriverSettingsSession = [NvAPIWrapper.DRS.DriverSettingsSession]::CreateAndLoad()
$New_Preferred_OpenGL_GPU = $DriverSettingsSession.CurrentGlobalProfile.Settings | where {$_.SettingInfo.Name -eq 'Preferred OpenGL GPU'}
write-host "#### New Preferred OpenGL GPU Value ####" -ForegroundColor Yellow
write-host "New Preferred OpenGL GPU: $($New_Preferred_OpenGL_GPU.CurrentValue | out-string)"
}
catch
{
write-output "[ERROR] An exception ocurred setting Preferrred OpenGL Value $_"
}
}
#----------------------------------------------
#endregion Example for changing Preferred OpenGL GPU from Autoselect to specific GPU
#----------------------------------------------
#----------------------------------------------
#region See what apps are using gpu
#----------------------------------------------
$GPUhandle = new-object NvAPIWrapper.Native.GPU.Structures.PhysicalGPUHandle
$GPU_apps = [NvAPIWrapper.Native.GPUApi]::QueryActiveApps($GPUhandle)
write-host "#### Apps Currently Using the GPU ####" -ForegroundColor Yellow
write-host "$($GPU_apps | out-string)"
#----------------------------------------------
#endregion See what apps are using gpu
#----------------------------------------------
#----------------------------------------------
#region Get GPU Clock Speeds and Current Usage
#----------------------------------------------
$physicalGPU = [NvAPIWrapper.GPU.PhysicalGPU]::GetPhysicalGPUs()
$physicalGPU_handle = $physicalGPU.handle
$GPU_clocks = [NvAPIWrapper.Native.GPUApi]::GetAllClockFrequencies($physicalGPU_handle)
$usages = [NvAPIWrapper.Native.GPUApi]::GetUsages($physicalGPU_handle)
write-host "#### GPU Clock Speeds ####" -ForegroundColor Yellow
write-host "$($GPU_clocks | out-string)"
write-host "#### GPU Current Usage ####" -ForegroundColor Yellow
write-host "$($usages | out-string)"
#----------------------------------------------
#region Get GPU Clock Speeds and Current Usage
#----------------------------------------------
#----------------------------------------------
#region Get Current Driver
#----------------------------------------------
$driver_branch_version = [NvAPIWrapper.NVIDIA]::DriverBranchVersion
$driver_Version = [NvAPIWrapper.NVIDIA]::DriverVersion
write-host "#### GPU Current Driver ####" -ForegroundColor Yellow
write-host "Driver Branch Version: $($driver_branch_version | out-string)"
write-host "Driver Version: $($driver_Version | out-string)"
#----------------------------------------------
#region Get Current Driver
#----------------------------------------------
#----------------------------------------------
#region Get Display HDR Data
#----------------------------------------------
$primary_display_device = [NvAPIWrapper.Display.DisplayDevice]::GetGDIPrimaryDisplayDevice()
#Get current hdr status/mode
$HDR_Current_Mode = new-object NvAPIWrapper.Native.Display.ColorDataHDRMode
write-host "#### GPU HDR Data ####" -ForegroundColor Yellow
write-host "HDR Driver Capabilities: $($primary_display_device.DriverHDRCapabilities.DisplayData | out-string)"
write-host "Current HDR Mode: $($HDR_Current_Mode)"
#----------------------------------------------
#region Get Display Capabilities and HDR Modes
#----------------------------------------------
#############################################################################
#endregion Execution and Output Functions
#############################################################################