powershell

Why is my locally-created script not allowed to run under the RemoteSigned execution policy?

懵懂的女人 提交于 2021-02-05 12:41:09
问题 Since this question continues to attract responses that are either refuted by the question body or don't address the actual problem, please read this simple summary of what you need to know: This is not a "Why won't my default installation of PowerShell run scripts?" question. This is not a "Why won't my installation of PowerShell run scripts downloaded from the internet?" question. The question is why the RemoteSigned execution policy is preventing script execution when it shouldn't.

How to import a module in a Azure PowerShell Function?

不羁岁月 提交于 2021-02-05 11:55:37
问题 Im trying to query an azure table from a function ( using Get-AzTableRow ) . Works very well from my laptop but the module "aztable' is not present in the azure function, and therefore all i get is a red screen :( Is there a way to install it ? Thanks ! David 回答1: You do not need to install the AzTable module in the Azure Function yourself. When you run the command, it will install the corresponding module for you. Here are the screenshots: The example of the AzTable module: $location =

Using Try Catch command to execute Powershell command remotely and then fallback with native command when failed?

喜你入骨 提交于 2021-02-05 11:51:22
问题 I'm trying to compile the script to manually connect to each server and then perform the Powershell command remotely, and if the Powershell module is not found, then failback to the native command. The script is like the following: Get-DfsrMember | Select-Object -ExpandProperty ComputerName -Unique | Sort-Object | ForEach-Object { $session = New-PSSession -ComputerName $_ Invoke-Command -Session $session -ScriptBlock { Try { # User Powershell Module DFSR to force Replicate all DFS server

PowerShell InvokeGet the directory property cannot be found

╄→尐↘猪︶ㄣ 提交于 2021-02-05 11:44:23
问题 We needed to retrieve the information in active directory concerning 'Terminal Services'. For this I've created a function that works fine most of the time. However, with some users we have issues. The code: Function Get-ADTSProfile { [CmdletBinding()] Param( [Parameter(Mandatory=$true,Position=0)] [String] $DistinguishedName, [parameter(Mandatory=$true,Position=1)] [ValidateNotNullOrEmpty()] [ValidateSet('UserProfile','AllowLogon','HomeDirectory','HomeDrive')] [String]$Property ) Begin {

How to replace a value in text file using powershell script

ⅰ亾dé卋堺 提交于 2021-02-05 11:26:10
问题 My file consists of following data (no header) DEPOSIT ADD 123456789 (VALUE)(VARIABLE) NNNN VALUEVARIABLE DEPOSIT ADD 234567890 (VALUE)(P75) NNNN VALUEVARIABLE DEPOSIT ADD 345678901 (VALUE)(VARIABLE) NNNN VALUEVARIABLE This is a tab delimited text file. There are total of 5 columns. (123456789 (VALUE)(VARIABLE) is a single value column) My requirements are: I need to fetch only the row which contains P75 to update in the same file. I have to replace the values in Col3,Col4 and in Col5 after

How to sort XML elements in powershell

左心房为你撑大大i 提交于 2021-02-05 11:16:26
问题 I have an XML: <project> <settings> <setting1 name="s1">foo</setting1> <setting2 name="s2">bar</setting2> </settings> <items> <item name="a"> <property1>foo1</property1> <property2>bar2</property2> </item> <item name="c"> <property1>foo3</property1> <property2>bar4</property2> </item> <item name="b"> <property1>foo5</property1> <property2>bar6</property2> </item> </items> </project> I need to sort the xml by attribute "name" of element "item". I'm doing something like this: [xml]$myXml = Get

How to get Caps Lock status on remote computer using powershell

微笑、不失礼 提交于 2021-02-05 10:43:07
问题 I have tried the following command but I only get a value of False : Invoke-Command -ComputerName Server01 -ScriptBlock {[console]::CapsLock} When I run [console]::CapsLock locally the command works. 回答1: Using [Console]::CapsLock The [Console]::CapsLock property can be read to get whether CapsLock is On or Off ( $true or $false ): [Console]::CapsLock You can also check the state of NumLock with [Console]::NumberLock as well. Using MS Word Seems that the remote session doesn't reflect whether

Getting the Final redirected URL from within PowerShell

天涯浪子 提交于 2021-02-05 10:41:43
问题 I'm finding similar answers, but not exactly what I'm needing. The backstory: I'm trying to write a powershell script that will scrape the Chrome and Microsoft Edge (chromium-based) extensions directory and output the name, ID, and version into a custom WMI class so that my endpoint management agent can accurately reflect user-installed extensions within the inventory record. In Chrome, this is reasonably easy even if the manifest.json doesn't include a human-readible "name" property, because

Getting the Final redirected URL from within PowerShell

依然范特西╮ 提交于 2021-02-05 10:41:05
问题 I'm finding similar answers, but not exactly what I'm needing. The backstory: I'm trying to write a powershell script that will scrape the Chrome and Microsoft Edge (chromium-based) extensions directory and output the name, ID, and version into a custom WMI class so that my endpoint management agent can accurately reflect user-installed extensions within the inventory record. In Chrome, this is reasonably easy even if the manifest.json doesn't include a human-readible "name" property, because

Powershell to trigger a build in Azure DevOps

半腔热情 提交于 2021-02-05 09:59:10
问题 We have just migrated our code from on-site TFS to Azure DevOps. With TFS, I use a powershell script to build and deploy the application. The deployment part still works fine, but I don't know how to trigger the build. The command line I used with the old TFS is: & "F:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TFSBuild" start [repository URL] [project] "[build definition]" I know that DevOps has a REST API https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds