powershell-2.0

How to iterate the irregularly-named children of an Xml.XmlElement in Powershell?

本秂侑毒 提交于 2020-01-15 04:25:07
问题 I have an XML file of the following format: <xml> <data> <foo float="99.0"/> <bar float="12.0"/> <tribble bool="true"/> ... <flibble int="1"/> </data> </xml> If I fetch that data in Powershell, I can see all the child elements of data with a Get-Memeber: > $xmlData = [xml](Get-Content myfile.xml) > $xmlData.data | Get-Member ... foo Property System.Xml.XmlElement ... bar Property System.Xml.XmlElement ... tribble Property System.Xml.XmlElement ... ... And I can access each child element

How to iterate the irregularly-named children of an Xml.XmlElement in Powershell?

烈酒焚心 提交于 2020-01-15 04:24:01
问题 I have an XML file of the following format: <xml> <data> <foo float="99.0"/> <bar float="12.0"/> <tribble bool="true"/> ... <flibble int="1"/> </data> </xml> If I fetch that data in Powershell, I can see all the child elements of data with a Get-Memeber: > $xmlData = [xml](Get-Content myfile.xml) > $xmlData.data | Get-Member ... foo Property System.Xml.XmlElement ... bar Property System.Xml.XmlElement ... tribble Property System.Xml.XmlElement ... ... And I can access each child element

Alter behaviour of every cmdlet in Powershell session to pass verbose flag

跟風遠走 提交于 2020-01-14 19:15:22
问题 If I wanted to alter the behaviour of every cmdlet in a Powershell session to pass verbose flag I could achieve this in Powershell v3 with $PSDefaultParameterValues like so $PSDefaultParameterValues['*:Verbose'] = $true What would be a possible workaround for Powershell v2? 回答1: No, this is a 'new' feature in PowerShell 3.0 and up: about_Parameters_Default_Values 来源: https://stackoverflow.com/questions/28808908/alter-behaviour-of-every-cmdlet-in-powershell-session-to-pass-verbose-flag

$MyInvocation.MyCommand.Path is $null in PowerGUI script editor

北战南征 提交于 2020-01-14 10:28:26
问题 When trying to debug my powershell script in the powerGUI script editor (2.0.0.1082) the $MyInvocation.MyCommand.Path is $null. It works when running the script via powershell. Running it in Powershell_ise.exe (on one of our servers) also works fine. Have anyone else had the same problem or know what's wrong? Here's my powershell version: Name Value ---- ----- CLRVersion 2.0.50727.4927 BuildVersion 6.1.7600.16385 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0}

PowerShell to delete Desktop Items from a remote PC

若如初见. 提交于 2020-01-13 20:39:13
问题 I have 200 PC that need to have some specific icons removed. I created a CSV file with the ComputerName (1 name per row) I have another file with the file name of the icon that needs to be removed from the desktops (Shortcut1.lnk, etc). This other file is also a CSV (1 file name per row). How can I run a PowerShell script to remove those icons. (Please note that not all computers in my CSV file maybe turned on. Some maybe off or have network issues). $SOURCE = "C:\powershell\shortcuts"

How to obtain email of the logged in user in powershell

白昼怎懂夜的黑 提交于 2020-01-13 08:07:12
问题 Using Vbscript , we are getting current user email id. It is as simple as with following lines. Option Explicit Dim objUser, objADSysInfo Set objADSysInfo = CreateObject("ADSystemInfo") Set objUser = GetObject("LDAP://" & objADSysInfo.UserName) WScript.Echo objUser.Mail How to achieve the same using powershell? 回答1: PS> $searcher = [adsisearcher]"(samaccountname=$env:USERNAME)" PS> $searcher.FindOne().Properties.mail 回答2: I'd be concerned that the given answer doesn't use the fully qualified

Adding and Removing Xmlnode using Powershell

点点圈 提交于 2020-01-13 07:51:46
问题 I am trying to add and remove elements from multiple xml files. i ran into two issue. it removed empty elements automatically and second it did not remove what i wanted to I have my xml like this <Entity> <App> <item1>1</item1> <emptyItem/> <person> <itemToRemove>true</itemToRemove> <emptyItem/> <otheritem>1</otheritem> </person> <person> <itemToRemove>false</itemToRemove> <emptyItem/> <otheritem>3</otheritem> </person> <person> <itemToRemove>false</itemToRemove> <emptyItem/> <otheritem>3<

Checking for a range in Powershell

久未见 提交于 2020-01-13 06:13:25
问题 I'm trying to write a script that will get an IP address of a computer and check to see whether it falls in a specific range of IPs. So for example, if the IP of the machine is 192.168.0.5, the script will check to see if it falls between the range 192.168.0.10 to 192.168.0.20. So far, my script is only able to get IPs of remote machines, but I just can't figure out how I would check if the IP is in a specific range. I'd appreciate any suggestions. Thank you. 回答1: It might be easiest to let

Powershell - Loop script until user chooses to exit

自作多情 提交于 2020-01-13 03:40:26
问题 How can I start a script over again? I have 3 switches and I want them to revert back to the beginning of the script. Import-Module ActiveDirectory Write-Host "--Please Login using a.account--" #login $credential = Get-Credential #Main Write-Host "--Remote Computer Rename v2.0--" Write-Host "1. Query AD (Outputs to a text file)" Write-Host "2. Quick computer rename" Write-host "3. Quit" $choice=Read-Host "Chose a number to continue" #AD Query for computer switch ($choice) { 1 { Write-Host "-

How do I install PCSX Powershell module?

荒凉一梦 提交于 2020-01-12 06:45:14
问题 I'm running Windows 7 with PowerShell 2 installed. I've downloaded version 2.1 from here - http://pscx.codeplex.com/releases The Release notes say unblock the zip file - {which I did} extract the contents of the ZIP file to your $env:Home\Documents\WindowsPowerShell\Modules folder I was unsure what $env:Home was so a bit of searching determined that the release notes are expecting an environment variable called Home which doesn't exist on my machine. A bit more searching says use what is