powershell-2.0

Comparing csv files in Powershell using Compare-Object

痞子三分冷 提交于 2019-11-26 17:22:01
问题 I am new to powershell and I having a little dilemma with a script I created to compare two csv files. The first csv has only one column called "Database Name" in it. The secound csv has a many columns and I only care about two of them "Database Name" and "Host Name". Right now the script compares only the "Database Name" column which works great!! and exports to Differences.csv. However, I would also like to see the corresponding "Hostname" column for each "Database Name" in the difference

powershell : changing the culture of current session

你。 提交于 2019-11-26 17:13:14
问题 I am using powershell on windows vista. How do I change the culture of current session? My computer's culture is tr-TR so I am getting the error messages on Turkish. I would like to change to EN? any chance? 回答1: Have a look here: http://blogs.msdn.com/b/powershell/archive/2006/04/25/583235.aspx and here: http://poshcode.org/2226: function Set-Culture([System.Globalization.CultureInfo] $culture) { [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture [System.Threading.Thread]:

Delete files older than 15 days using PowerShell

瘦欲@ 提交于 2019-11-26 16:55:37
I would like to delete only the files that were created more than 15 days ago in a particular folder. How could I do this using PowerShell? deadlydog The given answers will only delete files (which admittedly is what is in the title of this post), but here's some code that will first delete all of the files older than 15 days, and then recursively delete any empty directories that may have been left behind. My code also uses the -Force option to delete hidden and read-only files as well. Also, I chose to not use aliases as the OP is new to PowerShell and may not understand what gci , ? , % ,

Save hash table in PowerShell object notation (PSON)

二次信任 提交于 2019-11-26 16:45:23
The question Loading a PowerShell hashtable from a file? documents how to load a file that contains a hashtable in PSON format into a variable, but how does one save a hashtable to a file in PSON format? Hashtable: @{ "name" = "report 0" "parameters" = @( @{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4}, @{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'} ) } Try the *-CliXml cmdlets. To save the object: @{ "name" = "report 0" "parameters" = @( @{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4}, @{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'}

How to export data to CSV in PowerShell?

两盒软妹~` 提交于 2019-11-26 16:24:32
问题 foreach ($computer in $computerlist) { if((Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet)) { foreach ($file in $REMOVE) { Remove-Item "\\$computer\$DESTINATION\$file" -Recurse Copy-Item E:\Code\powershell\shortcuts\* "\\$computer\$DESTINATION\" } } else { Write-Host "\\$computer\$DESTINATION\" } } I want to export Write-Host "\$computer\$DESTINATION\" to the CSV files so I know which computers were offline when the script ran. I am running this from a Windows 7 machine

Is there a way to make a PowerShell script work by double clicking a .ps1 file?

我怕爱的太早我们不能终老 提交于 2019-11-26 15:43:30
I am distributing a PowerShell script to my team. The script is to fetch an IP address from the Vsphere client, make an mstsc connection, and log it in a shared file. The moment they used the script they got to know the IP address of machine. After that, they always tend to use mstsc directly instead of running the PowerShell script. (As they are using mstsc I am not able to know whether they are using the VM frequently or not.) Mainly they are telling me that running PowerShell is not straightforward. I am sick by their laziness. Is there a way to make a PowerShell script work by double

Methods to hex edit binary files via Powershell

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 14:24:15
问题 Am trying to perform binary hex edit from the command line using only powershell. Have had partial success performing a hex replace with this snip. Problem springs up when 123456 occurs multiple times and the replacement was only supposed to occur at a specific location. NOTE: The snip requires the Convert-ByteArrayToHexString and Convert-HexStringToByteArray functions found here. http://www.sans.org/windows-security/2010/02/11/powershell-byte-array-hex-convert $readin = [System.IO.File]:

copy-item With Alternate Credentials

流过昼夜 提交于 2019-11-26 13:05:47
问题 I\'m using the CTP of powershell v2. I have a script written that needs to go out to various network shares in our dmz and copy some files. However, the issue I have is that evidently powershell\'s cmdlets such as copy-item, test-path, etc do not support alternate credentials... Anyone have a suggestion on how best to accomplish my task..? 回答1: I have encountered this recently, and in the most recent versions of Powershell there is a new BitsTransfer Module, which allows file transfers using

Count items in a folder with PowerShell

。_饼干妹妹 提交于 2019-11-26 13:04:38
问题 I\'m trying to write a very simple PowerShell script to give me the total number of items (both files and folders) in a given folder ( c:\\MyFolder ). Here\'s what I\'ve done: Write-Host ( Get-ChildItem c:\\MyFolder ).Count; The problem is, that if I have 1 or 0 items, the command does not work---it returns nothing. Any ideas? 回答1: You should use Measure-Object to count things. In this case it would look like: Write-Host ( Get-ChildItem c:\MyFolder | Measure-Object ).Count; or if that's too

Powershell script to see currently logged in users (domain and machine) + status (active, idle, away)

泄露秘密 提交于 2019-11-26 12:58:33
问题 I am searching for a simple command to see logged on users on server. I know this one : Get-WmiObject -Class win32_computersystem but this will not provide me the info I need. It returns : domain Manufactureer Model Name (Machine name) PrimaryOwnerName TotalPhysicalMemory I run Powershell 3.0 on a Windows 2012 server. Also Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer | Select Antecedent -Unique gives me not the exact answers I need. I would love to see as well the idle time, or if