powershell

How do I add a PowerShell cmdlet or function to my machine so that it is always available?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 04:58:12
问题 If I find (or create) a new PowerShell cmdlet (or function), how do I add it to my machine? Do I copy it to a particular folder? Do I put its content in a particular file? Do I need to authorize it, or sign it, or give it permission in some way? I don't want to use it in just one session; I want it to be available whenever I use PowerShell on this machine. 回答1: As Alex mentions, any function defined in your profile or in a script that gets "dotted" into your profile will always be available.

Do curly braces mean anything in PowerShell variable declaration?

穿精又带淫゛_ 提交于 2021-02-07 04:55:16
问题 I have come across variables (or parameters) being declared like this: ${var_name} = "Hello world!" As far as I can tell, this is no different to the following: $var_name = "Hello world!" I am wondering if the {} braces in the first example do or mean anything. Do they change the behaviour of the variable? 回答1: Curly braces in PowerShell variable names allow for arbitrary characters in the name of the variable. If there are no "pathological" characters in the variable name, then the braces

Get CPU % of a particular process using powershell

穿精又带淫゛_ 提交于 2021-02-07 04:37:36
问题 I want to get the CPU usage % (not processor time) of a particular process using a powershell command. Example: (Windows 8 Task Manager) I want to get that 2.9% with a command. 回答1: Here is the correct answer which is support case then you have multiple processs with same name https://stackoverflow.com/a/34844682/483997 # To get the PID of the process (this will give you the first occurrance if multiple matches) $proc_pid = (get-process "slack").Id[0] # To match the CPU usage to for example

What is a List`1 object?

蓝咒 提交于 2021-02-07 04:24:12
问题 A System.IO.FileInfo has a Target member. Using Get-Item -Path * -Include 't.txt' | Get-Member shows it to have a Target member that is a CodeProperty . Using GetType() shows it to be a List`1 C:>Get-Item -Path * -Include 't.txt' | ForEach-Object { $_.Target.GetType() } IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True List`1 System.Object C:>Get-Item -Path * -Include 't.txt' | % { $_.Target.GetType() | % { $_.FullName } } System.Collections.Generic.List`1[[System

How to move a window between desktops using powershell/.net on windows 10

纵然是瞬间 提交于 2021-02-07 02:55:53
问题 I'd like to be able to using powershell start a process and move any windows created by that process to a particular virtual desktop. Any ideas? 回答1: The Windows SDK Support Team Blog posted a C# demo to switch Desktops via IVirtualDesktopManager: [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b")] [System.Security.SuppressUnmanagedCodeSecurity] public interface IVirtualDesktopManager { [PreserveSig] int

How to check if Docker is running on Windows?

被刻印的时光 ゝ 提交于 2021-02-07 02:43:30
问题 I'd like to know how to check if Docker is running on Windows by means of the command line (cmd or powershell). Although, I've found several posts indicating the solution to this, they are for Linux environments: How to check if docker is running or not How to check if docker daemon is running? I couldn't get the answer for Windows systems. 回答1: Try running either of these commands on Powershell or cmd, if docker is installed, you should get a error free response: docker --version OR docker

Change IIS Site Home Directory w/ Powershell

。_饼干妹妹 提交于 2021-02-07 02:31:10
问题 I can query the AD and find all the IIS sites and their virtual directories, now I need to be able to update those home directories and save the changes. After I fetch the directory entry I can display the site path using $site.Path , however setting it doesn't seem to have any effect. It never changes the actual stored path. I have tried $site.Path = <new path> and $site.Put( "Path", <new path> ) but neither have these seem to be affecting the stored path. $site = $iis.psbase.children |

Change IIS Site Home Directory w/ Powershell

可紊 提交于 2021-02-07 02:15:34
问题 I can query the AD and find all the IIS sites and their virtual directories, now I need to be able to update those home directories and save the changes. After I fetch the directory entry I can display the site path using $site.Path , however setting it doesn't seem to have any effect. It never changes the actual stored path. I have tried $site.Path = <new path> and $site.Put( "Path", <new path> ) but neither have these seem to be affecting the stored path. $site = $iis.psbase.children |

Change IIS Site Home Directory w/ Powershell

旧时模样 提交于 2021-02-07 02:09:56
问题 I can query the AD and find all the IIS sites and their virtual directories, now I need to be able to update those home directories and save the changes. After I fetch the directory entry I can display the site path using $site.Path , however setting it doesn't seem to have any effect. It never changes the actual stored path. I have tried $site.Path = <new path> and $site.Put( "Path", <new path> ) but neither have these seem to be affecting the stored path. $site = $iis.psbase.children |

Change IIS Site Home Directory w/ Powershell

狂风中的少年 提交于 2021-02-07 02:09:31
问题 I can query the AD and find all the IIS sites and their virtual directories, now I need to be able to update those home directories and save the changes. After I fetch the directory entry I can display the site path using $site.Path , however setting it doesn't seem to have any effect. It never changes the actual stored path. I have tried $site.Path = <new path> and $site.Put( "Path", <new path> ) but neither have these seem to be affecting the stored path. $site = $iis.psbase.children |