powershell-2.0

Powershell - calling icacls with parantheses included in parameters

穿精又带淫゛_ 提交于 2019-12-11 05:33:20
问题 I'm pretty new to Powershell, but I have lots of experience in VBScript and Python. I'm trying to be a good Windows admin and get into Powershell more. So, here is what I'm trying to do: A parent folder contains dozens of sub-folders that are named as AD usernames (ex. Users\username1, Users\username2, where Users is the parent folder). I want to loop through each folder name, parse out the sub-folder name, and pass that to icacls to apply permissions based on the username. I did a multi

Detecting Key Presses Across Applications in Powershell

邮差的信 提交于 2019-12-11 05:00:00
问题 This is a post that can be found on Powershell.com via Wayback machine. It is from 2015 and is not on the site anymore. A link to it is here: Detecting Key Presses Across Applications. This post is meant to be Archival. 回答1: By accessing the Windows low-level system calls, PowerShell can query the keyboard for pressed keys. The following example waits until the user presses 'A'. This is a simple example that does not consider the state of the SHIFT keys, nor does it check virtual keys.

PSCustomobject returrning strange output

一世执手 提交于 2019-12-11 04:29:01
问题 i have a script which is supposed to run a test-connection and a test-netconnection on three servers, for now i'm doing test with "localhost" the thing is i want the it will make at least two times the "test-connection" and it does, but the output is very strange (from the logical point of view is reasonable, but from the output point of view it's not) here is the code: if i use the count parameter and set it to 1 time, the output is correct it shows one pc from which it made the test, if i

Get only computer names from AD

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:48:21
问题 I'm new to Power Shell and I'm testing some commands and ideas. I'm stuck on what I feel should be pretty simple. I want to pull the names of computer objects in AD in to a file. The method I'm trying so far is this $computers = Get-ADComputer -Filter * | Format-List name write($computers) | Out-File -FilePath .\computers.txt the issue I have with this though is that the file that is output looks like this name : SERVER1 name : SERVER2 name : WORKSTATION1 name : WORKSTATION2 And I'm looking

Powershell - Change windows 7 background to image off a website

北城余情 提交于 2019-12-11 02:47:40
问题 set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value Zapotec.bmp I found this code online for Powershell for windows 7, however I want the wallpaper to be set to a file stored on a webserver accessible from a browser. how would i go about doing this. 回答1: I tried to change my wallpaper with your command but it didn't work until I ran this: rundll32.exe user32.dll, UpdatePerUserSystemParameters. Even then, it only worked intermittently (it's a know issue on Win7). Anyways

Identify if any string in one array exists in second array of strings with PowerShell

谁都会走 提交于 2019-12-11 02:34:03
问题 I have two arrays that I'm working with. Once that holds a set of criteria stored as strings, and one that is dynamically generated based on the result of a lookup performed earlier in my script. What I need to do is determine if ANY of the strings in the criteria array are present in the dynamic array so that I can do some conditional routines. # The criteria array used for comparison $criteria = "sysadmin", "dbadmin", "netadmin" What'd I'd like to do from this point is if the dynamic array

Using Powershell to Manipulate IP Restrictions on IIsWebVirtualDir

空扰寡人 提交于 2019-12-11 01:46:40
问题 Having trouble using Powershell to manipulate IP Restrictions on IIsWebVirtualDir (Virtual Directories). However, i have the code to do this in VBS, so hopefully this will be a simple matter to get help with :) Code in VBS: Sub Add2IPRList(WebsiteADSI, strIP2Add, strIP2AddSubnet) Set WebRootObj = GetObject(WebsiteADSI) '"IIS://localhost/W3SVC/2/ROOT/TestVDIR" set IPSecObj = WebRootObj.IPSecurity If(IPSecObj.GrantByDefault)then IPList = IPSecObj.IPDeny Else IPList = IPSecObj.IPGrant End If

What exactly does PowerShell's -Version parameter do?

好久不见. 提交于 2019-12-11 01:43:03
问题 PowerShell's help ( powershell -? ) states: -Version Starts the specified version of Windows PowerShell. However, when starting PowerShell 2 with powershell -Version 1 all things I tried that are only present in v2 and not v1 still work, such as the -split operator or the Get-Random cmdlet. So what exactly changes when running PowerShell with the -Version parameter if language features and cmdlets that were introduced later still exist and work? This makes testing scripts for PowerShell v1 a

How to detect whether a script is dot-sourced, or loaded as part of a module using powershell v2+?

*爱你&永不变心* 提交于 2019-12-11 01:19:31
问题 Given a ps1 file as part of a module with the following code: function Get-Greeting { 'Hello {0}' -f $Env:Username } Export-ModuleMember -Function:Get-Greeting When loaded as part of the module, everything is fine. If I dot-source the script, I get Export-ModuleMember : The Export-ModuleMember cmdlet can only be called from inside a module. I know I could just add a -ErrorAction:Ignore on the Export-ModuleMember, but that's not the point. I'd like to have a script run differently whether it

powershell Get-Counter -ComputerName parameter on Windows 7

血红的双手。 提交于 2019-12-11 00:39:45
问题 When I try to use the Get-Counter cmdlet on Windows 7 running as administrator I get the following error. Get-Counter -computername "$env:ComputerName" '\Memory\Available MBytes' Get-Counter : Unable to connect to the specified computer or the computer is of fline. At line:1 char:12 + Get-Counter <<<< -computername "$env:ComputerName" '\Memory\Available MBytes ' + CategoryInfo : InvalidResult: (:) [Get-Counter], Exception + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands