Search Results

Search found 1743 results on 70 pages for 'powershell'.

Page 19/70 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • PowerShell ISE: Multi-line Comment and Uncomment Done Right, and other ISE GUI must haves

    - by deadlydog
    Originally posted on: http://geekswithblogs.net/deadlydog/archive/2013/06/19/powershell-ise-multi-line-comment-and-uncomment-done-right-and-other.aspxI’ve written some code that you can add to your ISE profile that adds keyboard shortcuts to quickly comment and uncomment lines in PowerShell ISE.  Feel free to skip the Preamble and get right to the good stuff. Read more at http://blog.danskingdom.com/powershell-ise-multiline-comment-and-uncomment-done-right-and-other-ise-gui-must-haves/

    Read the article

  • My PowerShell functions do not appear to be registered

    - by Frank
    Hi there, I have a script saved in a ps1 file in which I define 2 functions as such: function Invoke-Sql([string]$query) { Invoke-Sqlcmd -ServerInstance $Server -Database $DB -User $User -Password $Password -Query $query } function Get-Queued { Invoke-Sql "Select * From Comment where AwaitsModeration = 1" } In the PowerShell console I then call the ps1 file by typing it in (it's in a folder in the path, and autocompletion works) However, I cannot start using the functions. I am confused, because when I copy / paste the functions into the console, all is fine and they work. I also have a function defined in my profile, and it works. Where am I thinking wrong, why doesn't it work what I'm trying to do?

    Read the article

  • .net, using PowerShell class to invoke a "[namespace.class]::method" style command

    - by Marco
    Hello, I created a powershell object via .net to invoke commands. When I invoke normal commands like 'Get-Process' I had no problems: ps.AddCommand("Get-Process").AddParameter(...).Invoke() but I'm not able to invoke a .net method with the syntax "[namespace.class]::method", just to make an example to invoke [System.IO.File]::Exists("c:\boo.txt"). I tried with ps.AddCommand("[System.IO.File]::Exists(\"c:\boo.txt\")").Invoke() ps.AddCommand("[System.IO.File]::Exists").AddArgument("c:\boo.txt\").Invoke() and some others. It always throws an exception which says that the command specified is not recognized. There is a way to invoke that type of command? Thanks

    Read the article

  • Change write-host output color based on foreach if elseif outcome in Powershell

    - by Emo
    I'm trying to change the color of write-host output based on the lastrunoutcome property of SQL Server jobs in Powershell....as in...if a job was successfull, the output of lastrunoutcome is "Success" in green....if failed, then "Failed" in red. I have the script working to get the desired job status...I just don't know how to change the colors. Here's what I have so far: # Check for failed SQL jobs on multiple servers [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null foreach ($svr in get-content "C:\serverlist2.txt") { $a = get-date $BegDate = (Get-Date $a.AddDays(-1) -f d) + " 12:00:00 AM" $BegDateTrans = [system.datetime]$BegDate write-host $svr $srv=New-Object "Microsoft.SqlServer.Management.Smo.Server" "$svr" $srv.jobserver.jobs | where-object {$_.lastrundate -ge $BegDateTrans -and $_.Name -notlike "????????-????-????-????-????????????"} | format-table name,lastrunoutcome,lastrundate -autosize foreach ($_.lastrunoutcome in $srv.jobserver.jobs) { if ($_.lastrunoutcome = 0) { -forgroundcolor red } else {} } } This seems to be the closest I've gotten...but it's giving me an error of ""LastRunOutcome" is a ReadOnly property." Any help would be greatly appreciated! Thanks! Emo

    Read the article

  • How to pass a variable as an argument to a command with quotes in powershell

    - by da_ponc
    Hi there, My powershell script takes the following parameter: Param($BackedUpFilePath) The value that is getting passed into my script is: "\123.123.123.123\Backups\Website.7z" I have another variable which is the location I want to extract the file: $WebsiteDeploymentFolder = "C:\example" I am trying to extract the archive with the following command: `7z x $BackedUpFilePath -o$WebsiteDeploymentFolder -aoa I keep getting the following error: Error: cannot find archive The following works but I need $BackedUpFilePath to be dynamic: `7z x '\123.123.123.123\Backups\Website.7z' -o$WebsiteDeploymentFolder -aoa I think I need to pass $BackedUpFilePath to 7z with quotes but they seem to get stripped out no matter what I try. I am in quote hell. Thanks.

    Read the article

  • Powershell: error handling with try and catch

    - by resolver101
    I'm writing a script and want to control the errors. However im having trouble finding information on error handling using the try, catch. I want to catch the specific error (shown below) and then perform some actions and resume the code. What code is needed for this? This is the code i am running and im entering in a invalid username when prompted. Get-WMIObject Win32_Service -ComputerName localhost -Credential (Get-Credential) Get-WmiObject : User credentials cannot be used for local connections At C:\Users\alex.kelly\AppData\Local\Temp\a3f819b4-4321-4743-acb5-0183dff88462.ps1:2 char:16 + Get-WMIObject <<<< Win32_Service -ComputerName localhost -Credential (Get-Credential) + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    Read the article

  • Filtering and copying with PowerShell

    - by Bergius
    In my quest to improve my PowerShell skills, here's an example of an ugly solution to a simple problem. Any suggestions how to improve the oneliner are welcome. Mission: trim a huge icon library down to something a bit more manageable. The original directory structure looks like this: /Apps and Utilities /Compile /32 Bit Alpha png /Compile 16 n p.png /+ 10 or more files /+ 5 more formats with 10 or more files each /+ 20 or so icon names /+ 22 more categories I want to copy the 32 Bit Alpha pngs and flatten the directory structure a bit. Here's my quick and very dirty solution: $dest = mkdir c:\icons; gci -r | ? { $_.Name -eq '32 Bit Alph a png' } | % { mkdir ("$dest\" + $_.Parent.Parent.Name + "\" + $_.Parent.Name); $_ } | gci | % { cp $_. FullName -dest ("$dest\" + $_.Directory.Parent.Parent + "\" + $_.Directory.Parent) } Not nice, but it solved my problem. Resulting structure: /Apps and Utilities /Compile /Compile 16 n p.png /etc /etc /etc How would you do it?

    Read the article

  • Replacement for Azure SDK Powershell commandlets for deployments

    - by Frank Rosario
    Hi, We've run into an issue with the New-Deployment Azure Powershell commandlet timing out; we've put in a bug report with MS. While they gave us an explanation for it (the path and timeout threshold used to upload through commandlets is different then what's used by the web portal); they don't have a fix for us. We need to get this running so we can automate our build deployments, so we're looking into developing a custom commandlet to replace New-Deployment using the Azure SDK; hoping this path will not have the timeout issues the commandlet did. But before we go down that route; are there any other scriptable tools I can use to replace the New-Deployment functionality? I looked at Cloudberry for Windows Azure; but that doesn't have a scriptable interface yet. Any constructive input is greatly appreciated.

    Read the article

  • PowerShell: Read text, regex sort, write output to file and formatting

    - by Bill Hunter
    I am a Powershell novice and have run into a challenge in reading, sorting, and outputting a csv file. The input csv has no headers, the data is as follows: 05/25/2010,18:48:33,Stop,a1usak,10.128.212.212 05/25/2010,18:48:36,Start,q2uhal,10.136.198.231 05/25/2010,18:48:09,Stop,s0upxb,10.136.198.231 I use the following piping construct to read the file, sort and output to a file: (Get-Content d:\vpnData\u62gvpn2.csv) | %{,[regex]::Split($, ",")} | sort @{Expression={$[3]}},@{Expression={$_[1]}} | out-file d:\vpnData\u62gvpn3.csv The new file is written with the following format: 05/25/2010 07:41:57 Stop a0uaar 10.128.196.160 05/25/2010 12:24:24 Start a0uaar 10.136.199.51 05/25/2010 20:00:56 Stop a0uaar 10.136.199.51 What I would like to see in the output file is a similar format to the original input file with comma dilimiters: 05/25/2010,07:41:57,Stop,a0uaar,10.128.196.160 05/25/2010,12:24:24,Start,a0uaar,10.136.199.51 05/25/2010,20:00:56,Stop,a0uaar,10.136.199.51 But I can't quite seem to get there. I'm almost of the mind that I'll have to write another segment to read the newly produced file and reset its contents to the preferred format for further processing. Thoughts?

    Read the article

  • Using SQLite from PowerShell on Windows 7x64?

    - by jas
    I'm having a difficult time trying to load System.Data.SQLite.dll from PowerShell in Windows 7 x64. # x64 [void][System.Reflection.Assembly]::LoadFrom("C:\projects\PSScripts\lib\System.Data.SQLite.x64.DLL") # x86 #[void][System.Reflection.Assembly]::LoadFrom("C:\projects\PSScripts\lib\System.Data.SQLite.DLL") $conn = New-Object -TypeName System.Data.SQLite.SQLiteConnection $conn.ConnectionString = "Data Source=C:\temp\PSData.db" $conn.Open() $command = $conn.CreateCommand() $command.CommandText = "select DATETIME('NOW') as now, 'Bar' as Foo" $adapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter $command $dataset = New-Object System.Data.DataSet [void]$adapter.Fill($dataset) Trying to open the connection with the x64 assembly results in: Exception calling "Open" with "0" argument(s): "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)" Trying to load the x86 assembly results in: Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\projects\PSScripts\lib\System.Data.SQLite.DLL' or one of its dependencies. An attempt was made to load a program with an incorrect format." Any thoughts or ideas?

    Read the article

  • Powershell function that creates a array by input

    - by user2971548
    I'm quite new to Powershell and working on a little project with functions. What I'm trying to do is creating a function that takes 2 arguments. The first argument ($Item1) decides the size of the array, the second argument ($Item2) decides the value of the indexes. So if I write: $addToArray 10 5 I need the function to create a array with 10 indexes and the value 5 in each of them. The second argument would also have to take "text" as a value. This is my code so far. $testArray = @(); $indexSize = 0; function addToArray($Item1, $Item2) { while ($indexSize -ne $Item1) { $indexSize ++; } Write-host "###"; while ($Item2 -ne $indexSize) { $script:testArray += $Item2; $Item2 ++; } } Any help is appreciated. Kind regards Dennis Berntsson

    Read the article

  • Run a SQL Script Against MySQL using Powershell

    - by abarr
    I have a Powershell script that backs up my MySQL DB's each night using mysqldump. This all works fine but I would like to extend the script to update a reporting db (db1) from the backup of the prod db (db2). I have written the following test script but it does not work. I have a feeling the problem is the reading of the sql file to the CommandText but I am not sure how to debug. [system.reflection.assembly]::LoadWithPartialName("MySql.Data") $mysql_server = "localhost" $mysql_user = "root" $mysql_password = "password" write-host "Create coonection to db1" # Connect to MySQL database 'db1' $cn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection $cn.ConnectionString = "SERVER=$mysql_server;DATABASE=db1;UID=$mysql_user;PWD=$mysql_password" $cn.Open() write-host "Running backup script against db1" # Run Update Script MySQL $cm = New-Object -TypeName MySql.Data.MySqlClient.MySqlCommand $sql = Get-Content C:\db2.sql $cm.Connection = $cn $cm.CommandText = $sql $cm.ExecuteReader() write-host "Closing Connection" $cn.Close() Any assistance would be appreciated. Thanks.

    Read the article

  • Powershell Replace Regex

    - by Brad
    I have a select-string which is seaching an IIS log for a particular string and returning the 2 lines above and one line below. So results look like this: 2012-06-15 18:26:09 98.138.206.39 OutboundConnectionResponse SMTPSVC1 WEB10 - 25 - - 220+mta1083.sbc.mail.ne1.yahoo.com+ESMTP+YSmtp+service+ready 0 0 60 0 218 SMTP - - - - 2012-06-15 18:26:09 98.138.206.39 OutboundConnectionCommand SMTPSVC1 WEB10 - 25 EHLO - WEB10.DOMAINCOM 0 0 4 0 218 SMTP - - - - 2012-06-15 18:26:09 74.125.244.10 OutboundConnectionResponse SMTPSVC1 WEB10 - 25 - - 550+IP+Authorization+check+failed+-+psmtp 0 0 41 0 218 SMTP - - - - 2012-06-15 18:26:09 74.125.244.10 OutboundConnectionCommand SMTPSVC1 WEB10 - 25 RSET - - 0 0 4 0 218 SMTP - - - - Note the third line begins with denoting thats the line that select-string matched upon. I am trying to do a -replace on the to replace it with < font color="red"$1< /font but my replace doesn't seem to work. Here's my code: $results = $results -replace "(^ )(.*)$", "< font color='red'$1< font" Can any powershell regex guru's out there tell me why my regular expression isn't matching? Thanks Brad

    Read the article

  • Using PowerShell class to invoke a "[namespace.class]::method" style command

    - by Marco
    Hello, I created a powershell object via .net to invoke commands. When I invoke normal commands like 'Get-Process' I had no problems: ps.AddCommand("Get-Process").AddParameter(...).Invoke() but I'm not able to invoke a .net method with the syntax "[namespace.class]::method", just to make an example to invoke [System.IO.File]::Exists("c:\boo.txt"). I tried with ps.AddCommand("[System.IO.File]::Exists(\"c:\\boo.txt\")").Invoke() ps.AddCommand("[System.IO.File]::Exists").AddArgument("c:\\boo.txt").Invoke() and some others. It always throws an exception which says that the command specified is not recognized. There is a way to invoke that type of command? Thanks

    Read the article

  • Powershell - Select the values of one property on all objects of an array

    - by Sylvain Reverdy
    Sorry, I'm still a noob on Powershell and I could not find an answer on Internet... Let's say we have an array of objects $objects. Let's say these objects have a "Name" property. This is what I want to do $results = @() $objects | %{ $results += $_.Name } this works but can it be done on a better way? If I do something like : $results = objects | Select Name $results is an array of objects having a Name property. I want $results to contain an array of Names So, is there a better way ? Thx a lot

    Read the article

  • Powershell equivilent of python's if __name__ == '__main__':

    - by Mark Mascolino
    I am really fond of python's capability to do things like this: if __name__ == '__main__': #setup testing code here #or setup a call a function with parameters and human format the output #etc... This is nice because I can treat a Python script file as something that can be called from the command line but it remains available for me to import its functions and classes into a separate python script file easily without triggering the default "run from the command line behavior". Does Powershell have a similar facility that I could exploit? And if it doesn't how should I be organizing my library of function files so that i can easily execute some of them while I am developing them?

    Read the article

  • powershell loop

    - by jvcoach23
    I'd like to use a windows powershell to run a batch file every x number of seconds. So it's the same batch file being run over and over again. I've done some looking but can't find what i'm looking for. It's for something that i want to run on a windows xp machine. Windows Schedular i've used lot of times before for somethign similar, but for some reason schedular only runs once.. then no more. i also don't want to have the batch file call itself, because it will error out after it runs so many times. thanks shannon

    Read the article

  • How to parse string from column in csv in Powershell

    - by user1445620
    I have a csv configured as such: PK,INV_AMT,DATE,INV_NAME,NOTE 1,123.44,634,asdfljk,TEST 12OING 06/01/2010 DATE: 04/10/2012 2,123.44,634,wet aaa,HI HOW ARE YOU 11.11 DATE: 01/01/2011 3,123.44,634,dfssdsdfRR,LOOK AT ME NOW….HI7&&& DATE: 06/11/1997 4,123.44,634,asdfsdgg,LOOK AT ME NOW….HI7&&& DATE: 03-21-2097 5,123.44,634,45746345,LOOK AT ME NOW….HI7&&& DATE: 02/18/2000 How can I parse the date after the string "DATE:" in the note column using powershell? For example, the first row has the string "TEST 12OING 06/01/2010 DATE: 04/10/2012" in the note column. I need to parse '04/10/2012' out of that row. I would like to be able to read from a csv file such as the one above and parse out that date and add it as a new column in the csv file. Thanks for any help.

    Read the article

  • How to Get SharePoint PowerShell to use .NET 2

    - by EoRaptor013
    I'm having a couple of problems with PowerShell. First, the PS configuration installed by SharePoint 2010 keeps popping this message: The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered. I've googled that, and given everybody and their second cousin Sharepoint_Shell_Access to the config DB, with no luck. So, I wanted to try some of the PS commands. In this case, however, I'm getting a different error: Microsoft SharePoint is not supported with version 4.0.30319.17929 of the Microsoft .Net Runtime. I get that SP can't use .NET 4.0 or 4.5, but I can't find any suggestions on how to get PS to use the "right" version of .NET. I've found some references for something called PowerGUI, and changing the psgui.exe.config, but I don't have that. Does anybody have any suggestions on how to solve the .NET version problem? Thanks.

    Read the article

  • PowerShell: How to add XmlElement to a non-root element

    - by Ariel
    I'm having trouble adding an XmlElement to a non-root element in PowerShell. Basically, given this xml: <clubs> <club name="boca" position="1"> <field>bombonera</field> <field>bombonerita</field> </club> <club name="racing" position="19"> <field>cilindro</field> </club> </clubs> I create an element, $new = $clubs.CreateElement("Barracas") When I try to add this element to a non-root node i.e. $clubs.clubs.club += $new I get Cannot set "club" because only strings can be used as values to set XmlNode properties. What am I missing? Thanks in advance.

    Read the article

  • how to query list in powershell

    - by Varyanica
    add-type -Language CSharpVersion3 -TypeDefinition @" public class pack_code { public pack_code() {} public string code { get; set; } public string type { get; set; } } "@ $a = New-Object pack_code $a.code = "3" $a.type = "5" $b = New-Object pack_code $b.code = "2" $b.type = "5" $c = New-Object pack_code $c.code = "2" $c.type = "5" $d = New-Object pack_code $d.code = "1" $d.type = "1" $codes = New-Object 'System.Collections.Generic.List[object]' $codes.add($a) $codes.add($b) $codes.add($c) $codes.add($d) is there a way to select distinct from $codes and select the objects where type equals 1? How can i use linq with PowerShell?

    Read the article

  • Introduction into handling errors in PowerShell for SQL Server tasks

    PowerShell is becoming a great tool for managing SQL Server tasks, but like most tasks that are coded there is always the need for error handling to deal with the unknown. PowerShell has several options for handling and capturing error details and in this tip we will explain these options using PowerShell for SQL Server examples. What are your servers really trying to tell you? Find out with new SQL Monitor 3.0, an easy-to-use tool built for no-nonsense database professionals.For effortless insights into SQL Server, download a free trial today.

    Read the article

  • powershell folder stats

    - by huppy_doodoo
    Hi all, I keep all modules of our system in one dir (e.g. All\ModuleA; All\ModuleB). I want to see what types of files are most numerous and take up the most space, by module. So, I'd like output along the lines of: ModName,java-count,java-size,xml-count,xml-size,png-count,png-size... ModuleA,30,0.2,100,2.3,0,0,... ModuleB,21,0.1,20,0.7,1,1.2 Not all modules have files of all types, so this will only work if I list all types for all module (with lots of zeros). I have something that almost works, but it's hideous, verbose and inefficient. I'm sure someone can help me see the light :-) (which, by the way, can be a piece of freeware software that does this out of the box; I only chose to do this in powershell out of interest). thanks

    Read the article

  • Powershell - remote folder availability while counting files

    - by ziklop
    I´m trying to make a Powershell script that reports if there´s a file older than x minutes on remote folder. I make this: $strfolder = 'folder1 ..................' $pocet = (Get-ChildItem \\server1\edi1\folder1\*.* ) | where-object {($_.LastWriteTime -lt (Get-Date).AddDays(-0).AddHours(-0).AddMinutes(-20))} | Measure-Object if($pocet.count -eq 0){Write-Host $strfolder "OK" -foreground Green} else {Write-Host $strfolder "ERROR" -foreground Red} But there´s one huge problem. The folder is often unavailable for me bacause of the high load and I found out when there is no connection it doesn´t report an error but continues with zero in $pocet.count. It means it reports everything is ok when the folder is unavailable. I was thinking about using if(Test-Path..) but what about it became unavailable just after passing Test-Path? Does anyone has a solution please? Thank you in advance

    Read the article

  • Handling null values with PowerShell dates

    - by Tim Ferrill
    I'm working on a module to pull data from Oracle into a PowerShell data table, so I can automate some analysis and perform various actions based on the results. Everything seems to be working, and I'm casting columns into specific types based on the column type in Oracle. The problem I'm having has to do with null dates. I can't seem to find a good way to capture that a date column in Oracle has a null value. Is there any way to cast a [datetime] as null or empty?

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >