w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Get name/version number WMI/Powershell query (eventually for all machines on domain)
Check out the examples for Where-Object. They show how to filter properly. Also, Get-WmiObject can be painfully slow. Better to add the filter using its Query or Filter parameters. Again, read the help topic for some examples.

Categories : Powershell

How to set up Spark cluster on Windows machines?
FYI, I got an answer in the user-group: https://groups.google.com/forum/#!topic/spark-users/SyBJhQXBqIs The standalone mode is indeed the way to go. Mesos does not work under Windows and YARN probably neither.

Categories : Apache

Is there any way to prevent my application from running on Windows 7 machines?
You can use System.Environment.OSVersion, but the best approach is to make your application run and look correctly on Windows 7 too, you don't really want to lose the clients that have Windows 7 (especially now when that is the most used Windows version)

Categories : C#

Powershell script running fine on Windows 8 but not on Windows 7
The error indicates you didn't correctly set the execution policy. Firstly, you have run Powershell as an administrator. To do this, right click on the Powershell icon in the start menu and click on "Run as Administrator". Next you have to run the following command in Powershell: Set-ExecutionPolicy RemoteSigned You will be prompted to allow the change. Type "Y" and press return. Finally, try running your script.

Categories : Powershell

Unable to connect to Windows Azure from Powershell Azure Powershell module
To see is there some result from Import-AzurePublishSettingsFile you can call: Get-AzureSubscription By default it select the default to current subscription. If you don't see any result then you don't import your subscription settings right. This Introduction to Windows Azure PowerShell also can help you.

Categories : Windows

Azure VM pricing - Is it better to have 80 single core machines or 10 8-core machines?
Billing According to Windows Azure Virtual Machines Pricing Details, Virtual Machines are charged by the minute (of wall clock time). Prices are listed as hourly rates (60 minutes) and are billed based on total number of minutes when the VMs run for a partial hour. In July 2013, 1 Small VM (1 virtual core) costs $0.09/hr; 8 Small VMs (8 virtual cores) cost $0.72/hr; 1 Extra Large VM (8 virtual cores) cost $0.72/hr (same as 8 Small VMs). VM Sizes and Performance The VMs sizes differ not only in number of cores and RAM, but also on network I/O performance, ranging from 100 Mbps for Small to 800 Mbps for Extra Large. Extra Small VMs are rather limited in CPU and I/O power and are inadequate for workloads such as you described. For single-threaded, I/O bound applications such as describe

Categories : Azure

Add Column to CSV Windows PowerShell
Here's one way to do that using Calculated Properties: Import-Csv file.csv | Select-Object *,@{Name='column3';Expression={'setvalue'}} | Export-Csv file.csv -NoTypeInformation You can find more on calculated properties here: http://technet.microsoft.com/en-us/library/ff730948.aspx. In a nutshell, you import the file, pipe the content to the Select-Object cmdlet, select all exiting properties (e.g '*') then add a new one.

Categories : Powershell

Windows SDK environment and powershell
You can launch an instance of CMD.EXE, run SetEnv.cmd, and then launch PowerShell from within the CMD window. The PowerShell instance that opens up will import the environment variables from the CMD instance that spawned it. It's ugly, but it works. I wrote a batch script to do it for me, and just created a shortcut to it on my desktop. Here's an example: @echo off call "C:PathToSetEnv.cmd" param1 param2 param3 powershell.exe -noexit

Categories : Windows

Sending mail with Powershell Windows 7
This could be due to many reasons, but one issue that I had seen this exact same error was because an anti-virus program was blocking Powershell from sending the email. Check if this is the case by looking at your anti virus logs. Beyond that, you might want to check if firewall is fine, you can connect to the SMTP server etc.

Categories : Email

Closing All Explorer Windows in PowerShell
I think there's something in the pipeline that goes wrong. This code works: $a = (New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? { $_.FullName.toLower().Endswith('explorer.exe') } $a | % { $_.Quit() }

Categories : Powershell

How can I set IIS Windows Auth Providers with powershell?
You can only enable and disable the authentication methods available under the following section: system.webServer/authentication This is because system.webServer/authentication is not a collection and does not support the add and remove config elements. Have a look in the IIS configuration schema file in: C:WindowsSystem32inetsrvconfigschemaIIS_schema.xml Search for system.webServer/security/authentication and you will see that each child element of that section is explicitly defined and there is no definition for system.webServer/security/authentication itself. With regards to ordering, it makes no difference trying to change the authentication method order. For example in the following order (Basic is before Windows Authenticaton): <system.webServer> <security

Categories : Powershell

Why does C# Powershell method work in Windows app but not Web app
You should note that when you do create a profile, it can be user or machine specific. Also, it can be scoped for all shells or just powershell. http://technet.microsoft.com/en-us/magazine/2008.10.windowspowershell.aspx

Categories : C#

Windows Azure Powershell Copying file to VM
You cannot use PowerShell to copy a file directly to a Virtual Machine's OS disk (or even to one of its attached disks). There's no API for communicating directly with a Virtual Machine's innards (you'd need to create your own custom service for that. You can use PowerShell to upload a file to a Blob, with Set-AzureStorageBlobContent. At that point, you could notify your running app (possibly with a Queue message?) on your Virtual Machine that there's a file waiting for it to process. And the processing could be as simple as copying the file down to the VM's local disk.

Categories : Powershell

Get-ScheduledTask in PowerShell on Windows Server 2003
You'll find all the informations you need about the missing COM object in Working with scheduled tasks from Windows PowerShell. Using Windows Server 2012 you can use Scheduled Tasks Cmdlets in Windows PowerShell.

Categories : Powershell

Simple way to get CPU load from Windows Server via PowerShell
Assuming the $Servers collection to be populated with host names, you are not that far off. I don't have the Quest tools, so am unable to check the collection. # Best practice: avoid mistyped variable names set-psdebug -strict $Servers = Get-QADComputer -sizelimit 0 | where {$_.Name -like "*myserver*"} | select Name # Best practice: avoid magic numbers; readonly variable for new-variable -name CPULIMIT -value 75 -option readonly foreach($Server in $Servers){ $result = Get-WmiObject win32_processor -ComputerName $Server.Name # TODO: add error handler here in case $server is unavailable # Compare the wmi query result to the limit constant if($result.LoadPercentage -le $CPULIMIT){ # Write a formatted string that contains the server name and current load Writ

Categories : Powershell

Running PowerShell script in a C# Windows Service App
Here is a pretty good discussion on how to call Powershell from C#: http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C I suggest you start with the RunScript function and add it to a VS2010 console application. Main() would then invoke RunScript something like RunScript( "echo 'hello from PS';get-date; get-culture; "). Windows services have quite a few differences from a normal console application. You can read about how to write a windows service on MSDN, but if you've never coded before, you have a steep learning curve in front of you. There is a service from an old Resource Kit call srvany.exe (Google it) which would run any console app as a service. However in Windows Vista (and above) services were restricted from accessing the desktop, so srvany could

Categories : C#

Generating Powershell scripts by working in Windows GUI
I don't have the exact answer to your question, but the things you may have read/heard about on some blog or podcast are : first : The Start-Transcript and Stop-Transcrip CmdLets that allow you to record all the command lines you type at the PowerShell prompt. Second : As you are using PowerShell 3 you are using ISE which is now, a not so bas PowerShell editor. But it was not so at the begining and I was using a free editor from Quest Software called PowerGUI. When you download this editor it comes with an other soft called administrative console. This administrative console allow you generate PowerShell for basic operations and comes with a WMI browser that also generate PowerShell scripts. Third : It exists also a PowerShell Scriptomatic, but I just never use it.

Categories : Powershell

PowerShell/Windows scripting: Get interface name containing a specified gateway IP
maybe you can use InterfaceIndex to link this objects: get-wmiObject -Query "select InterfaceIndex from Win32_NetworkAdapter" get-wmiObject -Query "select InterfaceIndex from Win32_NetworkAdapterConfiguration" InterfaceIndex Data type: sint32 Access type: Read/write IP address of the next hop of this route. The value in this property is the same as the value in the InterfaceIndex property in the instances of Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration that represent the network interface of the next hop of the route. In the case of a route bound to an interface that is realized using a broadcast medium, the value of this field is the agent IP address on that interface. description from: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394162(v=vs.85).aspx someth

Categories : Misc

setting NTP server on Windows machine using PowerShell
From a bit of googling about w32tm vs control panel date/time, I found this, which appears to be what you need. Hope that helps you out :-)

Categories : Powershell

Find unique/distinct files in windows powershell.
cd c:Folder ls | ? { -not $_.PSIsContainer -and $_.BaseName -cmatch 'Esd{2}' } | % { $folder = $matches[0] new-item -ItemType Directory -Path . -Name $folder -ErrorAction SilentlyContinue move-item $_.Name $folder } Idk if this helps, but I suggest more research. If you were talking about just doing ls | ? {$_.Name -cmatch "Esd{2}"} | select unique That might not be very useful

Categories : Sorting

Powershell remoting: Cannot connect to Windows 2012 EC2 Instance
First you need to sort out if a connection can be established to the remote machine. Easiest is to try the following command from the windows command prompt: telnet <ip> 5985 If the telnet client is not installed, add it via add/remove windows components. If a connection is not possible, you will get an error. This is the most likely error. Possible reasons: Client side firewall (local or network) preventing the connection EC2 Security group configuration Server firewall rule. Since you can access the remote machine over remote desktop, run the same command on the server to make sure that the WinRM service is actually working and listening on the default port. If a connection is possible from the client machine, open the event viewer on the server and go to: "Applications and

Categories : Windows

Git GUI/TortoiseGit Not calling hooks that use powershell correctly? (Windows)
I think I saw this happen once before. The ExecutionPolicy is different when in an interactive shell vs a shell spawned by a script. Try this: c:/windows/system32/WindowsPowerShell/v1.0/PowerShell.exe -ExecutionPolicy:Bypass -Command "New-Item File.txt -type file"

Categories : GIT

Error While uploading to windows Azure using powershell Script
I moved my script to the virtual machine which is hosted on azure and this error is no more so i think this error was due to my firewall or due to the slow internet connection.the script is running as desired on the virtual machine and i am able to automate my deployment process.

Categories : Asp Net

Windows Powershell - Cannot create a html table correctly
I too suspect it's related to how you're building the custom object within the foreach-object loop; after playing a while I gave up and tried to build it from scratch. Hopefully this will work for you. Before your Get-ChildItem call create an empty array: $tableObject = @() Then change your foreach-object block to fill the array iteratively with the contents of the psobject: ForEach-Object { $properties = "" | Select Directory, Name, DateModified $properties.Directory = $_.Directory $properties.Name = $_.Name $properties.DateModified = $_.LastWriteTime $tableObject += $properties } Finally, outside of the foreach-object block add the table, passing the array without having to select anything: $script:M

Categories : Windows

Windows Powershell - Returning and supplying variables to functions does not work
In your do-while look, $MyReport is just passed to the print everything method. But, it will not be in scope at that point as you are just assigning to $MyReport within the functions. Try using $MyReport as $script:MyReport everywhere, so that it will be in script scope. This is not the ideal solution, but should be good enough to get you started. Also, you might want to read up on pipeline / function output in powershell. You are using it wrong - http://stacktoheap.com/blog/2013/06/15/things-that-trip-newbies-in-powershell-pipeline-output/

Categories : Function

Installing Windows Features on remote server 2012 using powershell 3.0
Personally I would use the latter (directly call Install-WindowsFeature -ComputerName $server rather than do a separate Invoke-Command) in this case for the following reasons: You may be hard-coding the feature names now, but in the future you may want to put those in a variable. If you put them in a variable, you'll have to pass it as a parameter into the Invoke-Command's script block. This is entirely possible, but more work. By using your own loop, you can write progress messages, logging, etc. You gain nothing by using Invoke-Command in this case because you're running a single command on the remote computer (as opposed to running multiple commands with -ComputerName parameters vs. running multiple commands inside the script block).

Categories : Powershell

Can I control Windows 7 Task Scheduler conditions with Powershell Script?
Check out this blog, http://www.vinithmenon.com/2012/11/powershell-v3-scheduled-job-to-start.html, it has steps on how to use scheduled tasks module in powershell, you would need to get powershell V3

Categories : Powershell

powershell 'system.windows.media.mediaplayer' Register-ObjectEvent
Add-Type -AssemblyName PresentationCore $_MediaPlayer = New-Object System.Windows.Media.MediaPlayer $_MusicFolder = 'C:UsersMaking JESUS ProudMusic' $_MusicFiles = Get-ChildItem -path $_MusicFolder -include *.mp3 -recurse $duration = $null foreach($_file in $_MusicFiles){ "Playing $($_file.BaseName)" [uri]$_song = $_file.FullName do { $_MediaPlayer.Open($_song) $_songDuration = $_MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds } until ($_songDuration) $_MediaPlayer.Volume = 1 $_MediaPlayer.Play() Start-Sleep -Milliseconds $_songDuration $_MediaPlayer.Stop() $_MediaPlayer.Close() }

Categories : Powershell

Trouble creating multiple folders from a TXT file in Windows PowerShell or CMD?
The "workaround" for the "`Set-ExecutionPolicy error'" is to set the execution policy to allow scripts to run. See http://technet.microsoft.com/en-us/library/ee176961.aspx . It's set to the most restrictive by default but any admin worth his salt will set it to something less restrictive based on what the environment requires. Once you've done that, your script looks solid.

Categories : Windows

How can you close a specific Windows comObject by a trait like location name? Powershell
Figured it out.. (New-Object -comObject Shell.Application).Windows() | where-object {$_.LocationURL -eq "File:///C:/Scripts/Whatever/Folder/Path"} | foreach-object {$_.quit()} In case anyone else is dumb like me :)

Categories : Windows

Gather [System.Windows.Forms.Screen]::AllScreens via Powershell remotely
No, this is not possible. Screen.AllScreens does not have a remote version so you need to use PowerShell remoting to call that method on a remote machine. If you use PowerShell remoting you end up in a PowerShell Windows Service which has a default desktop. This desktop is not visible, belongs to the system account and has no real screens. Therefore it will simply not give you the result you want. Also see here.

Categories : Powershell

How do I grant SeBatchLogon privileges to a domain account on a Windows server with Powershell?
Use ntrights.exe from the Windows Server 2003 Resource Kit Tools: ntrights +r SeBatchLogon -u mydomainatchuser

Categories : Powershell

Convert filename in a folder from upper case to lower case (Windows Command Prompt or PowerShell)
In PowerShell: Get-ChildItem | Rename-Item -NewName { $_.Basename.ToUpper() + $_.Extension } or shorter: ls | ren -n { $_.Basename.ToUpper() + $_.Extension }

Categories : Windows

Why would installing Azure SDK 2.1 or powershell 3 on the build server break some of our tests which run in powershell?
Have you tried passing a fully qualified path to startInfo.FileName instead of just Powershell.exe incase there's a problem with %PATH% since the update Complete total guess, but any chance your running into FileSystemRedirector 32 vs. 64 issues as seen in this answer - Process.Start(): The system cannot find the file specified, but my file path seems to be legit

Categories : Powershell

Add Powershell Snapin for Powershell Module and Import Multiple Times
You might want to try to specify this module required by your own module through a module manifest (.psd1). See RequiredModules here.

Categories : Powershell

Executing Powershell script as different User in Exchange 2007 Powershell
I just found out that executing Remote Powershell Commands/Skripts is not supported with Exchange 2007 (http://howexchangeworks.com/2009/11/exchange-2007-sp2-supports-powershell.html). So I need to wait until the upgrade to 2013. Some workarounds: http://social.technet.microsoft.com/Forums/en-US/exchangesvrgeneral/thread/4596035a-cede-4541-8b8e-e2e9bf1b40dc Or: http://peerfect.blogspot.co.at/2012/10/re-blog-of-my-exchange-remote.html

Categories : Powershell

PowerShell Community Extensions not Recognized by TeamCity PowerShell Runner
Do you import the PSCX module in your script? PowerShell v3 will cache the module info after you have done this once so you don't need to import it again. However if TeamCity is running the 64-bit console and you normally run the 32-bit console, then the 64-bit console wouldn't have PSCX commands in the command cache. Anyway, it is a good practice to have your scripts explicitly require the modules it depends upon e.g. #requires -Modules Pscx

Categories : Powershell

x:set not working the same on 2 different machines?
I'll throw up my workaround incase anyone else has this issue in the future. No matter what I did, I couldn't figure out why some machines were just refusing to recognise/implement the string() xpath function, so I worked around the problem by changing my code to the following: <c:set var="test2"> <x:out select="$extraSideNavLinks/sideNavLinks/@perm"/> </c:set> This worked consistently on all machines.

Categories : Java

How can I use ADT on both my Mac and Linux Dev Machines
Try syncing only the actual code files you create, not the project itself (i/e file1.java if you're writing in java, file2.cpp if in C++, etc). You might have to monkey around with adding new files, but that should be as simple as importing/exporting. You're going to have all kinds of trouble syncing paths for 2 different machines... Otherwise try a free source control like assembla

Categories : Android

How do I return value or object from C# powershell command to Powershell
You have to use the CmdLet.WriteObject method. Here a good explanation from @RomanKuzmin.

Categories : Powershell



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