powershell-2.0

Copy file remotely with PowerShell

允我心安 提交于 2019-12-28 01:42:09
问题 I am writing a PowerShell script that I want to run from Server A. I want to connect to Server B and copy a file to Server A as a backup. If that can't be done then I would like to connect to Server B from Server A and copy a file to another directory in Server B. I see the Copy-Item command, but I don't see how to give it a computer name. I would have thought I could do something like Copy-Item -ComputerName ServerB -Path C:\Programs\temp\test.txt -Destination (not sure how it would know to

Get remote registry value

浪子不回头ぞ 提交于 2019-12-27 17:39:30
问题 I have the below script that I want it to go out to multiple servers and get the value of a registry. Unfortunately it is currently just posting back the local registry value of the machine that I am running the script on. How do I get the script to run against remote registry? SCRIPT: clear #$ErrorActionPreference = "silentlycontinue" $Logfile = "C:\temp\NEWnetbackup_version.log" Function LogWrite { param([string]$logstring) Add-Content $Logfile -Value $logstring } $computer = Get-Content

Get remote registry value

社会主义新天地 提交于 2019-12-27 17:39:08
问题 I have the below script that I want it to go out to multiple servers and get the value of a registry. Unfortunately it is currently just posting back the local registry value of the machine that I am running the script on. How do I get the script to run against remote registry? SCRIPT: clear #$ErrorActionPreference = "silentlycontinue" $Logfile = "C:\temp\NEWnetbackup_version.log" Function LogWrite { param([string]$logstring) Add-Content $Logfile -Value $logstring } $computer = Get-Content

How can I read file input without any pre-defined path in PowerShell?

做~自己de王妃 提交于 2019-12-25 09:19:09
问题 I have users provide an input txt file as an argument -InputFile which I store as $inputfile . But when I try: $reader = [System.IO.File]::OpenText("$inputfile") PowerShell automatically appends the $inputfile path to C:\Windows\system32. How can I have PowerShell not assume a path prefix, so a user could simply pass -InputFile inputfile.txt if the file they want is in the same directory from which they run the script? How can I also support them enumerating a completely different path to the

Powershell to set GPO

空扰寡人 提交于 2019-12-25 08:25:51
问题 I want to set the value of "Inclusion list for Moderate risk file Types" to enable and add a file extension to the list. The key exists in : User Configuration>Administrative Templates>Windows Components>Attachment Manager How can I use powershell to turn this on and off ? 回答1: To create a GPO based on a registry key on a W2K8 R2 computer, the roadmap is the following Import the Active-Directory module : Import-module activeDirectory Create a GPO and link it to an OU : New-GPO -Name "MyGPO" |

Unexpected result of Reflection.AssemblyName().Version

末鹿安然 提交于 2019-12-25 07:59:21
问题 Recently, I had to check assembly version of certain DLL, let call it AAA.BBB.dll and I decided to use a simple Powershell command to get it, namely: [Reflection.AssemblyName]::GetAssemblyName('AAA.BB.dll').Version I realized that this command does not display the version that I want. Most of the time it displays one fixed version which does not match the version of the dll in the current directory. Even providing an some invalid inputs to GetAssemblyName method (e.g. 'AAA.BB.dll123') showed

How to pass a Hex String to a TCP connection and Read the Result

廉价感情. 提交于 2019-12-25 07:15:06
问题 I have the following script (thanks to @SavindraSingh for the link). I am trying to pass the $message below to the $remotehost $port and capture the response. $port=12345 $remoteHost = "1.2.3.4" $message="\x40\x00\x23\x01\x00\x00\x00\x40" $socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port) $data = [System.Text.Encoding]::ASCII.GetBytes($message) $stream = $socket.GetStream() $stream.Write($data, 0, $data.Length) The problem is that the ASCII.GetBytes converts each character

Add a column in excel sheet using powershell

前提是你 提交于 2019-12-25 05:09:28
问题 I want to add a column after a particular column number in excel sheet using Powershell. I am able to add it at starting of sheet, but couldn't insert after a specific column. 回答1: Alas, I agree, I have not found neither documentation or examples :-/ . Nevertheless here is below how to insert a column 7th and give it a name: (Get-ChildItem "*.xlsb")| foreach-object { $xl=New-Object -ComObject Excel.Application $wb=$xl.workbooks.open($_) $ws = $wb.worksheets.Item(1) $ws.Columns.ListObject

How to sync 2 shares on LastWriteTime without deletion

孤街醉人 提交于 2019-12-25 03:13:51
问题 I need to synchronize 2 FTP repertories behind 2 different servers wich are not member of a cluster IIS. A virtual IP is used to do have a kind of failover. I tried with robocopy or xcopy needs to have a reference directory. In my case, when the task is launched by a third server, I just need to copy the last written files and directory which are not in the other one. $Global:pathFTP1 = $SRV1unc + "\c$\inetpub\PlcmSpIp" $Global:pathFTP2 = $SRV2unc + "\c$\inetpub\PlcmSpIp" $Global:Files1 = @()

Powershell 2.0 Format-list output to JSON?

匆匆过客 提交于 2019-12-25 01:55:52
问题 PS B:\abrabackups> . C:\ps\ConvertTo-JSON.ps1 PS B:\abrabackups> Get-ItemProperty -Path .\AbraSuite01.03.2014 | select Name,CreationTime | ConvertTo-JSON And that gives me: (formatted for clarity) { "CreationTime": "2014-01-03T16:48:36", "Name": "AbraSuite01.03.2014" } Well that's all well and good, but suppose I want my dates in a different format in the JSON string, is there anyway to do this in powershell and still use my shoehorned ConvertTo-JSON.ps1 for powershell 2.0? 回答1: Convert your