powershell-2.0

Powershell tasks from local machine to remote machine

岁酱吖の 提交于 2019-12-11 13:59:08
问题 I am performing below tasks on remote machine from a local machine: Creating/Deleting/Modifying some directory Copying some folder from local to remote machine Installing some .exe silently with noninteractive option Exectuing some batch files I want to write a script in PowerShell. Novice to PowerShell. I have done some basic investigation of terms like "PowerShell Remoting" etc. What are the things I need to look for? Related exmple for this will help, where should I look for those? 回答1:

How to make a messagebox appear at a specific time in PowerShell?

别等时光非礼了梦想. 提交于 2019-12-11 13:12:12
问题 I want to create an alarm clock that displays a specific event using a messagebox. Using the code provided: [System.Windows.Forms.MessageBox]::Show("Do this task" , "Alert!") Do { $waitMinutes = 1 $startTime = get-date $endTime = $startTime.addMinutes($waitMinutes) $timeSpan = new-timespan $startTime $endTime Start-Sleep $timeSpan.TotalSeconds # Play System Sound [system.media.systemsounds]::Exclamation.play() # Display Message Show-MessageBox Reminder "Do this task." } # Loop until 11pm

Resolve-DnsName inside Test-Connection

馋奶兔 提交于 2019-12-11 13:04:01
问题 I was wondering how I could return the Resolve-DnsName output from my Test-Connection script and add it to the CSV I created. I like to capture the Name, Type, TTL, Section from that please. Only invoke the Resolve-DnsName when the ping is not successful. $servers = Get-Content "servers.txt" $collection = $() foreach ($server in $servers) { $status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) } $result = Test-Connection $server -Count 1 -ErrorAction SilentlyContinue if ($result)

How to remove Braces/Curly Brackets from output -Powershell

好久不见. 提交于 2019-12-11 12:58:38
问题 How to remove Braces/Curly Brackets from output $t = [ADSI]"WinNT://$env:COMPUTERNAME" $t1 = $adsi.PSBase.Children |where {$_.SchemaClassName -eq 'user'} $t1 |select Name,Fullname Name Fullname ---- -------- {Anon} {Anon Xen1} {Anon1} {Anon1 Xen2} {Anon2} {Anon2 Xen3} 回答1: The reason there are curly braces in the first place is because the Name and FullName properties are collections not strings. Specifically they are System.DirectoryServices.PropertyValueCollection objects. $t = [adsi]"WinNT

Run built-in cmdlet with parameters that may or may not be specified

天涯浪子 提交于 2019-12-11 12:56:11
问题 I've got a function in my script that wraps up the send-mailmessage cmdlet and does a bit of logic before sending out each email. My question is how do I create the argument list to feed into send-mailmessage so that Cc, Bcc, and Attachments are optional. What I'd done before is just a few if statements. But adding -Cc to the mix, that will be 9 if statements instead of the current 4. I figure I'm over-thinking this and there's got to be a simpler way. Stripped down Function: Function Send

How can I use Invoke-WmiMethod to rename a computer

旧城冷巷雨未停 提交于 2019-12-11 12:42:35
问题 I am trying to call the Rename method on the Win32_ComputerSytem class using Invoke-WMI method. Using this syntax works fine (gwmi win32_ComputerSystem).Rename("NEWNAME") This also works fine for demo purposes Invoke-WmiMethod -path win32_process -Name create -ArgumentList notepad However, when i try the following, I get an error 11 > Invoke-WmiMethod -path win32_computersystem -Name Rename -ArgumentList IwasRenamed Invoke-WmiMethod : Invalid method Parameter(s) At line:1 char:17 + Invoke

How to run multiple Scripts one by one in a powershell script

≯℡__Kan透↙ 提交于 2019-12-11 11:59:44
问题 I have 8 scripts in Powershell which I run one by one. Let's call the scripts: script1.bat, script2.bat, .., script8.bat . Now I need a script which runs all scripts.bat one by one, but not simultaneously. And is there a way to check, if each script was successful? 回答1: ./script1.bat ./script2.bat ./script3.bat ... You'll get the picture, I guess. This will run them in sequence. To determine whether they were sucessful or not that depends very much on how those batch files signal errors or

send-MailMessage not working

依然范特西╮ 提交于 2019-12-11 11:52:13
问题 I am using the send-MailMessage cmdlet in PowerShell version 2 and it gives me a error. I tried using all the options which were mentioned in the earlier posts and it didn't help me. This is the command that I am using: send-MailMessage -from "abc@gmail.com" -to "def@gmail.com" -subject "test" -body"test" -smtp "smtp.gmail.com" I get an error: Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated e was: 5.7.0 Must issue a STARTTLS command first.

How can I join the result of `ls` as a char separated string in PowerShell?

空扰寡人 提交于 2019-12-11 11:13:30
问题 I have a folder containing the following files: File_1.txt File_2.txt AnotherFile.txt I want to be able to achieve an output of: File_1.txt - File_2.txt I have tried running: ls .\file*.txt | %{$_.Name} which returns what I want except on separate lines, how can I join the files returned by a given character ( - in this example)? Any help is appreciated. 回答1: You can use the -join operator: (ls file*) -join ' - ' If you need more control about the individual items being joined here, just

how to include a “:” as a parameter in powershell?

浪尽此生 提交于 2019-12-11 10:56:20
问题 i have a simple powershell script, like this sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a" but i always got the error message Sqlcmd: ':a': Invalid argument. Enter '-?' for help. i figured out that it is the ":" in the argument caused the problem, but i do not know how to escape it. thanks, David 回答1: sorry that i have to answer to my own question again. the only way to solve this problem is to use '+' to concatenate the two string, and the ':' will be reserved. e.g. $a="abc"+":123" 回答2: You