powershell

List all the vm in a particular Subnet in Azure

佐手、 提交于 2021-01-29 07:17:43
问题 Just wondering how to retrieve the VMs details in a given particular subnet in Azure. I have used the below but it does not work anymore in powershell (Cloud shell) Listing all azure vm belonging to particular subnet Any help will be appreciated. Thanks 回答1: The following code snippet has been tested against my environment : $vms = Get-AzVM $tgtSubnet = "MySubnet" foreach($vm in $vms) { $networkInterface = Get-AzNetworkInterface -Name ($vm.NetworkProfile.NetworkInterfaces[0].Id.Split('/')[-1]

Powershell script to convert .csv to .html and handling multiple files

Deadly 提交于 2021-01-29 07:05:51
问题 I have to write a script that takes the content of multiple .csv files and write them into one .html file. The goal ist to see all filenames as buttons and be able to expand buttons to see the content. My problem is that I don't know how to give the data-target and div id the correct name for each file. I guess you figured out by now that my scripting skills are... very very limited but here is my try: $in = "C:\clientlist\*" $out = 'C:\clientlist\test.html' $head = @" <head> <link rel=

How can I wrap this Powershell cmdlet into a timeout function?

与世无争的帅哥 提交于 2021-01-29 07:00:44
问题 I've tried (and failed) to get [System.Delegate]::CreateDelegate( to work, New-Object [System.Threading.Tasks.Task]::Run(, to work, Start-Job with Wait-Job, Powershell does not seem to be setup to do an asynchronous task with a wait timeout? If anyone has any ideas, that'd be awesome. do { Sleep 2; $testShare = Test-Path "\\$server\c$"; Write-Host "Share availability is:" $testShare; }while($testShare -eq $true) # wait for the share to become unavailable Adams suggestion do { Sleep 1; #

Get SecureString as a Plain Text Parameter

本小妞迷上赌 提交于 2021-01-29 06:51:20
问题 I'm trying to get a SecureString as plain text parameter to a command line PowerShell. I know what is the form of the secure string. For example, the string "abc" would be a Secure String of "71289371289". Then, I want to pass "71289371289" as a parameter to the script (Running it from command line), that would be my Secure String and then Decrypt it to a clear text to pass it to another program i'm calling from Powershell. How would I do something like this? Update: I ended up using Credfile

Powershell function “if test-connection” true

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 06:33:13
问题 Heyy guys, i have a powershell script which is working fine but i want to expand it with another line. Here is what i have. $Path = "\\xyz\trigger1.txt" $Path2 = "$env:userprofile\xyz\trigger2.txt" if ((Test-Path $Path -PathType Leaf) -and (-not(Test-Path $Path2 -PathType Leaf))){ if((get-process "XXX" -ea SilentlyContinue) -eq $Null) { "not Running" copy-item "\\xyz\xyz\*" "$env:userprofile\def\" -recurse -ErrorAction SilentlyContinue start-sleep -s 5 } else { "running" stop-process -name

updating NSG Rule via powershell doesnt work

陌路散爱 提交于 2021-01-29 06:31:00
问题 I follow exactly what's on the Microsoft document but with no luck I'm trying to update the Priority rule from 120 to 4040 set-azurermnetworksecurityruleconfig code I follow: $nsg = Get-AzureRmNetworkSecurityGroup -Name EA-NSG-AAA -ResourceGroupName EA-RG $nsg | Get-AzureRmNetworkSecurityRuleConfig -Name name-02 Set-AzureRmNetworkSecurityRuleConfig -Name name-02 -NetworkSecurityGroup $nsg -Priority 4040 回答1: You are not updating the network security group in Azure, you are only modified your

AD users don't get added to groups by powershell

耗尽温柔 提交于 2021-01-29 06:08:48
问题 I have a script for adding a user to the active directory. The user gets created (although there are some issues for which I'll create separate questions), but the user is not added to the groups, with the error that groups were not found. But I confirmed the groups are in the AD. This is the code I have now: $Orig_exec_policy = Get-ExecutionPolicy Set-ExecutionPolicy Bypass -Force <# This form was created using POSHGUI.com a free online gui designer for PowerShell .NAME Untitled #> Add-Type

How to use Select-Xml in Powershell to print the content of an xml node element?

…衆ロ難τιáo~ 提交于 2021-01-29 06:00:39
问题 restricted to xpath or even Select-Xml how else are the book titles printed? PS /home/nicholas/powershell> PS /home/nicholas/powershell> Select-Xml "./bookstore.xml" -XPath "/bookstore/book/title" | foreach {$_.node.InnerXML} Pride And Prejudice The Handmaid's Tale Emma Sense and Sensibility PS /home/nicholas/powershell> PS /home/nicholas/powershell> Select-Xml -Path "./bookstore.xml" cmdlet Select-Xml at command pipeline position 1 Supply values for the following parameters: XPath:

Im having promlen with button functions in gui powershell

允我心安 提交于 2021-01-29 05:58:50
问题 I am struggling here. i cannot figure out how to make the button functions read the $listbox1.selectedItems and $listbox2.selectedItem whats wrong here? if i try to look at the $listbox items after the OK button been pressed it will show me but not if i call the function button, ive deleted some unneccesery code parts. $form = New-Object System.Windows.Forms.Form $form.StartPosition = 'CenterScreen' $button1 = New-Object System.Windows.Forms.Button $button1.Text = 'Link' $button2 = New-Object

PowerShell implementing -AsJob for a cmdlet

不问归期 提交于 2021-01-29 05:36:13
问题 Is there a nice way to implement the switch parameter -AsJob in custom cmdlets, like Invoke-Command has? The only way I thought about this is: function Use-AsJob { [CmdletBinding()] [OutputType()] param ( [Parameter(Mandatory = $true)] [string] $Message, [switch] $AsJob ) # Wrap Script block in a variable $myScriptBlock = { # stuff } if ($AsJob) { Invoke-Command -ScriptBlock $myScriptBlock -AsJob } else { Invoke-Command -ScriptBlock $myScriptBlock } } Is there a better approach? I couldn't