w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » POWERSHELL » Page 1
browse website with powershell without using internet explorer
There is no way of 'browsing' websites through Powershell, not in the traditional sense of the word anyway. However, you can download and upload content, create web service requests, login to websites, etc. through the web-client class and invoke-webrequest cmdlet. Again, not in anyway like a graphical browser, but very useful for repetitive tasks that do not require much human intervention

Categories : Powershell

Migrate a List from SharePoint 2007 to SharePoint 2010
Migrating sharepoint with powershell can be troublesome. Try using a tool instead such as metalogix migration: http://www.metalogix.com/Products/Content-Matrix.aspx?utm_source=adwords&utm_medium=cpc&utm_campaign=701a0000002EA67&utm_term=sharepoint%20online%20migration&utm_content=40325388985&gmt=b&gnw=g&gcr=40325388985&gpl=&gkw=sharepoint%20online%20migration&

Categories : Powershell

Powershell : Cannot compare array.Length with int32
The problem is the for statement you should write it like this: for ($i = 1; $i -le $input.Length; $i++) with ";" and not ",". I didn't check the rest of the code as your question was about $input.length and int32.

Categories : Powershell

Powershell Copy-Item - Exclude only if the file exists in destination
This should be pretty close to what you want to do $Source = "C:MyTestWebsite" $Destination = "C:inetpubwwwrootDemoSite" $ExcludeItems = @() if (Test-Path "$Destination*.config") { $ExcludeItems += "*.config" } if (Test-Path "$Destination*.csproj") { $ExcludeItems += "*.csproj" } Copy-Item "$Source*" -Destination "$Destination" -Exclude $ExcludeItems -Recurse -Force

Categories : Powershell

HTML Agility pack with ie COM object in PowerShell
To get page's source HTML code from Internet Explorer COM object use : $IE.Document.body.parentElement.outerHTML Source: How to view source HTML from an InternetExplorer Object? Barebone example: # Load HTML Agility Pack, assume it's alongside with the script Add-Type -Path '.HtmlAgilityPack.dll' # Create new HTML Agility Pack document $Hap = New-Object -TypeName HtmlAgilityPack.HtmlDocument

Categories : Powershell

powershell variable syntax $($a)?
$() is a subexpression operator. It means "evaluate this first, and do it separately as an independent statement". Most often, its used when you're using an inline string. Say: $x = Get-ChildItem C:; $x | ForEach-Object { Write-Output "The file is $($_.FullName)"; } Compare that to: $x = Get-ChildItem C:; $x | ForEach-Object { Write-Output "The file is $_.FullName"; } You can also

Categories : Powershell

Where are CSV files saved?
If you call PowerShell from a batch file, it will often start in C:WindowsSystem32 because that's where cmd.exe is. To set the location to where the script file being run is, you can use this: Set-Location $script:MyInvocation.MyCommand.Path If that doesn't work in PowerShell 2.0, try: Set-Location $MyInvocation.MyCommand.Path Check Get-Help about_Automatic_Variables for more information.

Categories : Powershell

Using Powershell to checkin zip file to TFS
use the tf command line Example for checkin: cd C:TFSArquitectura %ProgramFiles%Microsoft Visual Studio 9.0Common7IDETF.exe checkin $/Arquitectura/Main /recursive On Windows x64 "%ProgramFiles(x86)%Microsoft Visual Studio 10.0Common7IDETF.exe" checkin $/Arquitectura/Main /recursive See for more information on the tf commandline: http://msdn.microsoft.com/en-us/library/z51z7zy0(v=VS.90).aspx O

Categories : Powershell

Powershell: count members of a AD group
The `Get-ADGroupMember' cmdlet would solve this in a much more efficient way than you're tying. As an example: $users = Get-ADGroupMember -Identity 'Group Name' $users.count 132 EDIT: In order to clarify things, and to make your script simpler. Here's a generic script that will work for your environment that outputs the user count for each group matching your filters. $groups = Get-ADGroup -

Categories : Powershell

Why this code passing switch parameters to a PowerShell function fails
What happens is that: The parser looks at the provided argument: "-param1:$true" Fails to bind it to parameter param1, since the value you provided is a string, not a switch/bool No specific parameter type is required at position 0, argument is ignored If you make param1 positional, you can see how PowerShell fails to bind it properly: function test-parambinding {param([Parameter(Position=0)]

Categories : Powershell

Export-VM not found
Install the SCVMM 2012 R2 console on the workstation that you are wanting to run the Export-VM command on. This will install the appropriate powershell cmdlets, including Export-VM. I've tested this with Windows 7 x64 and SCVMM 2012 R2. The way you do this is to insert the CD/mount the ISO on the computer you would like to install the console on. Then when you run the install you should have the

Categories : Powershell

Sharing variables between jobs
You can't pass variables from one job to another. What you can do is have the jobs create a specific file on completion, and monitor for the existence of that file while they're running. Make the content of the script block so that the operation terminates without creating the marker file when the file is discovered. $block = { $marker = 'C:path omarker.txt' do while (-not ((Test-Path -Litera

Categories : Powershell

Powershell command-line throw
In the first version you're attempting to call a program called throw, thus it fails. It would actually work fine if you simply did: powershell -command "throw 'test'" In the second version, you use the curly braces, so the expression is evaluated by & as a script block rather than trying to invoke a program

Categories : Powershell

Powershell, find files containing keyword then rename those files
The following will look for all *.properties files and if they contain the keyword 'DataMonitor' the file will be renamed. Get-ChildItem -Path $directoryToTarget -Filter *.properties -Recurse | where { !$_.PSIsContainer } | % { $i = Get-Content $_ |Select-String "Datamonitor" -SimpleMatch if ($i -ne $null) { Rename-Item $_ -NewName ('Datamonitor_'+$_.name) } } One dra

Categories : Powershell

How to display list Active Directory users that arent in specific AD Groups
One approach: Export all users Export users that are members of that specific group Do excel work to find out users that aren't members However, if the task is to perform it with powershell only, you have to do your research how to perform those steps without excel.

Categories : Powershell

Powershell group labels in table
The Select-Object cmdlet allows you to add new (calculated) properties. You can use that for instance to resolve the service group name from a hashtable that you created before: $group = @{ 'pc1' = 'group 1' 'pc2' = 'group 1' 'pc3' = 'group 1' 'pc4' = 'group 2' 'pc5' = 'group 3' } Get-Service -computername pc1,pc2,pc3,pc4,pc5 -displayname '*something*' | Select-Object Status, Machine

Categories : Powershell

how can i supress error messages on a certain bloc of code in powershell
You can try changing the value of the $ErrorActionPreference variable: $errpref = $ErrorActionPreference #save actual preference $ErrorActionPreference = "silentlycontinue" ... your code ... $ErrorActionPreference = $errpref #restore prevuious preference

Categories : Powershell

Desired State Configuration credential private key not acquired
Okay, i'm not sure exactly why this works, but it does. Using the Computer template seems to work. In terms of work, powershell on the target node can see it's private key from dir cert:LocalMachineMy | ? PrivateKey -ne $null Once that happens it all works as expected. So long story short is don't use the workstation Auth template but the Computer template.

Categories : Powershell

Powershell invoke-command passing an object
If $LIST["COMPUTER"].SERVICES return list service of COMPUTER you can test in your scriptblock for every object passed..maybe This but not tested: (in pseudo-code) Icm -comp $LIST.FQDN -Script { Param($obj) $c=$env:computername $obj["$c"].services } -arg $LIST

Categories : Powershell

Add counter as suffix to all files in subfolders
If you want the counter to restart in each folder you need to separate folder recursion from enumerating/renaming the TIFF files in each folder. Try something like this: Get-ChildItem -LiteralPath 'C: est' -Recurse | ? { $_.PSIsContainer } | % { $cnt = 0 Get-ChildItem -LiteralPath $_.FullName -Filter '*.tif' | % { Rename-Item -LiteralPath $_.FullName -NewName ("IL-TRUM_{0}_{1}_{2:d4}{3}"

Categories : Powershell

PowerShell function parameters syntax
Don't call functions or cmdlets in powershell with parentheses and commas (only do this in method calls)! When you call a($svr, $usr) you're passing an array with the 2 values as the single value of the first parameter. It's equivalent to calling it like this a -svr $svr,$usr which means the $usr parameter is not specified at all. So now $x equals the string representation of the array (a join wi

Categories : Powershell

Powershell variable getting "lost"
I'm not sure of your intent, but I see a possible solutions. First, this code: $XMLtmp = foreach ($user in $XMLFile.POSLog.POSLogTransaction) { $user.RetailStoreID $user.WorkStationID $user.OperatorID $user.SequenceNumber } You never seem to use $XMLtmp again. Also, it's just going to contain an array of strings, not something that has properties like $user.RetailStoreID What you can d

Categories : Powershell

How to pass multiple value parameter to reporting services report via powershell
According to MSDN the ReportParameter.Values property is of type [StringCollection]. PowerShell can't easily cast the [String[]] into a [StringCollection]. See this article for an example of how to use [StringCollection] objects within PowerShell

Categories : Powershell

How to replace text in pipelined data without it converting the underlying object into a string object
Try this: $DnsData = Get-WmiObject -Class MicrosoftDNS_AType -NameSpace RootMicrosoftDNS -ComputerName "DCName" -Filter "DomainName = 'OurDomain.local'" ` |?{$_.IPAddress -like "192.168.100.*" } | Select-Object @{Name="OwnerName";Expression={$_.ownername -replace ".OurDomain.local",""}}, ipaddress

Categories : Powershell

Get the last object returned
I'm sure this wasn't exactly what you were looking for, but you may find it interesting. Stuffing the output of the last command into an automatic variable (get-powershell.com). Solution posted by Andy Schneider and inspired by comments from "//o//" and Joel. Here's a code snipped from the linked article to "override out-default" and store the results in a global variable like $lastobject. funct

Categories : Powershell

PowerShell get-child item and get-content a few folders deep
This should work: get-childitem -recurse -include Web.Config | foreach-object { $name = $_.FullName; get-content $name } | foreach-object {$_ -replace "Web1", "Web2" } | set-content $name I implore you to test this on an isolated temporary directory. You might want to try this at first: get-childitem -recurse -include Web.Config | foreach-object { $name = $_.FullName; get-content $name } | for

Categories : Powershell

FolderItem.Name does return name without file extension
FolderItem.Name return value depends on the value of particular Windows setting. Try the following: Open Control Panel, Folder Options, View tab, Uncheck Hide extensions for known file types. Re-run the script and you will see the expected output: Application : System.__ComObject Parent : System.__ComObject Name : file.txt Path : C: andomnamefile.txt ... I

Categories : Powershell

Powershell filter contents to find file or directory
I've not worked with that particular module so I can't debug anything there, but for your logic this is what I'd use: Import-Module NTFSSecurity; Get-Content C:Temp est.txt | ForEach-Object { If (Test-Path $_ -PathType Leaf) { If ((Get-Item $_).Extension -in ('.exe','.dll','.msc')) { #Apply executable file rule } } ElseIf (Test-Path $_ -PathType Container) {

Categories : Powershell

powershell passwordlastset export to spread sheet
By default not all properties are returned, so you need to specify the additional properties you want. Also, if you're looking for the last logon date (per your output), you should be using lastLogonTimestamp and not PasswordLastSet. Here's an example using Get-ADComputer, which I greatly prefer over using older methods of searching AD. Just add your Export-CSV when you're happy with the results

Categories : Powershell

Powershell 1.0 Set-Execution for LOCAL SYSTEM account
Based on this answer: http://stackoverflow.com/a/4647585/140377 you can just run Set-ExecutionPolicy RemoteSigned as an administrator and it will apply to all users.

Categories : Powershell

Rename files to md5 sum + extension on Windows 7 (with CMD or PowerShell 2013)
You didn't write what you've already got, so I won't explain the script. Just remember that you'll get an error for files with same md5. Get-ChildItem d: emp*.xxx | select FullName, Extension, @{name='md5'; expression={(Get-FileHash $_ -Algorithm md5).Hash}} | foreach {Rename-Item $_.FullName -NewName "$($_.md5)$($_.extension)"}

Categories : Powershell

powershell select-string output to file
Change the following line: $sel = select-string -list $htm -pattern $pattern | Select-Object Line To: $sel = select-string -list $htm -pattern $pattern | Select-Object -ExpandProperty Line That will ensure you write the property of the object rather than the textual representation of the object itself

Categories : Powershell

How PowerShell handles hashtable property values of complex types such as SPListItem that have their own properties?
Good Powershell le the item as a list normally. You can access all items in a list such as below: Add-PSsnapin Microsoft.SharePoint.PowerShell $SPAssignment = Start-SPAssignment #Read List $webS = Get-SPWeb "http://intranet.domain.com.br" $listS = $webS.Lists["List"] foreach($item in $listS.Items | Where { $_["ID"] -le 10}) { $item["Title"] = "Le id 10" $item.Update() $id = $item["

Categories : Powershell

Get-ChildItem inconsistent behavior, inserting a space when using variable in path
Why don't you use AD-GetComputer to pull all the PC names into a variable? You can also use export-csv is that would work better for you: $Computers= Get-ADComputer -Filter * -SearchBase "ou=accounting,dc=domain,dc=com" -Properties * | Select -ExpandProperty name foreach ($computer in $Computers) { Get-ChildItem \$computerc$users*AppDataRoaming*.dll -recurse | Export-Csv

Categories : Powershell

powershell v2, use cmdlet with parameters known only at truntime
using you example you can do it something like this: Function test ($value , [switch]$paramA, [switch]$paramB) { if ($paramA) { $cmd = "-filter $value" } if($paramB) { $cmd = "-exclude $value" } iex "dir $cmd" } to test it try it like this: test -value *.ps1 -paramA or test -value *.ps1 -paramB

Categories : Powershell

Powershell job with alternate credentials from Octopus Deploy
I tried the same thing without any luck, it seems like it's not possible to start jobs as a different user. In this similar question, Leblanc ended up using WinRM and Invoke-Command instead: run script block as a specific user with Powershell (I don't think this is anything Octopus specific - the issue seems to be more of a problem with SYSTEM being able to start processes as a different user, o

Categories : Powershell

How can I run vim from PowerShell just by typing vim?
If it's already in the path, it should work. But you can, alternatively, use an alias via New-Alias. If you add that to your profile, it will load every time. To see how to run box behaves differently than powershell, and how you might get around that, see my answer here: Run a program by name from PowerShell (similarly to the run box)

Categories : Powershell

Powershell functional zip equivalent
A bit cumbersome, but it works: Script file test.ps1: param( $fnop, $first, $second) $retval = @() $len = if($first.length -lt $second.length) { $first.length } else { $second.length } for( $i = 0; $i -lt $len; $i++) { $oprslt = $fnop.invoke( $first[$i], $second[$i]) $retval = $retval + $oprslt } $retval Example: # add and sort PS> . est.ps1 {param($a,$b) return $a+$b} (3,2,1)

Categories : Powershell

DNS setting update help and also Output results
Regarding your first question: Before your foreach loop create an empty array $arr=@() then in the loop add the output to the array $obj = gwmi win32_networkadapterconfiguration -cn $memberservers.name ... $arr+= $obj and after the loop export it $arr | export-csv

Categories : Powershell




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.