我目前有一个脚本可以ping服务器并检查每台服务器上运行的服务的状态.
我使用Out-File保存输出,但PowerShell在长字符串后放置省略号或"...".我不希望它这样做.例如:
MachineName ServiceName Status StartType
----------- ----------- ------ ---------
SrvGtw01 Test.MyService.... Running
Run Code Online (Sandbox Code Playgroud)
我希望它显示如下全名:
MachineName ServiceName Status StartType
----------- ----------- ------ ---------
SrvGtw01 Test.MyServiceName.Here Stopped Disabled
Run Code Online (Sandbox Code Playgroud)
我一直在阅读你可以设置$FormatEnumerationLimit偏好变量-1,我已经尝试过,但它没有用.我不确定如何将它放在我的脚本中.
我目前正在使用此示例使用 Go 连接到 SQL Server:
这是我正在使用的示例:
package main
import (
_ "github.com/denisenkom/go-mssqldb"
"database/sql"
"context"
"log"
"fmt"
)
// Replace with your own connection parameters
var server = "localhost"
var port = 1433
var user = "sa"
var password = "your_password"
var db *sql.DB
func main() {
var err error
// Create connection string
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d",
server, user, password, port)
// Create connection pool
db, err = sql.Open("sqlserver", connString)
if err != nil {
log.Fatal("Error creating …Run Code Online (Sandbox Code Playgroud) 我有一个运行Windows“ net user”命令的程序,以获取用户的到期日期。例如:“网络用户justinb / domain”
该程序获取到期日期。我正在使用该到期日期并将其设置为变量dadd
在下面的示例中,我们假设给定的到期日期为1/10/2018。(注意:Windows不会在当月前加0)
import time
datd = "1/10/2018"
# places a 0 in front of the month if only 1 digit received for month
d = datd.split("/")
if len(d[0])==1:
datd="0"+datd
print("Changed to: " + datd)
myDate = (time.strftime("%m/%d/%Y"))
print ("This is today's date: " + myDate)
if datd <= myDate: # if datd is is earlier than todays date
print (" Password expired. ")
else:
print (" Password not expired. ")
input(" Press Enter to …Run Code Online (Sandbox Code Playgroud) 我有一个将可执行文件和 .ps1 保存到远程计算机列表的脚本。然后在每台计算机上运行可执行文件。由于静默运行时的设置方式,我必须使用 .ps1 调用可执行文件。
我注意到我的一个命令从命令行快速运行,但似乎挂在我的脚本中。有什么理由会发生这种情况吗?
命令是:
psexec -s @C:\myscript\computers.txt cmd /c "Powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass && PowerShell -noninteractive -file "C:\Install.ps1""
Run Code Online (Sandbox Code Playgroud)
这是我的整个脚本:
cls #clear screen
function CopyFiles {
# Get .exe from source and place at destination workstation
$source2="\\mainserver\program.exe"
$destination2="\\$line\c$\program.exe" # place .exe on C:\ directory of worstation
Copy-Item -Recurse -Filter *.* -path $source2 -destination $destination2 -Force
# Get .bat from source and place at destination workstation
$source3="\\fileserver\Install.ps1"
$destination3="\\$line\c$\Install.ps1" # place .bat on C:\ directory of worstation
Copy-Item …Run Code Online (Sandbox Code Playgroud) 我决定看看 Go,但目前我陷入了困境。在此程序中,我要求用户选择选项 1 或 2。如果选择选项 1,我希望 ReadAppList 函数询问用户的姓氏。
似乎第二个 scanf 被跳过并且不允许用户输入姓氏。它只读取第一个用户输入吗?
package main
import (
"fmt"
)
// Main function that runs on startup
func main() {
fmt.Println("\n1. Search Last Name ")
fmt.Println("\n2. Exit ")
fmt.Println("\nPick an option: ")
var userAnswer int
fmt.Scanf("%d", &userAnswer)
if userAnswer == 1 {
ReadAppsList()
} else if userAnswer == 2 {
fmt.Println("\nGoodbye.")
} else {
fmt.Println("\nThat is not a valid choice.")
}
}
func ReadAppsList() {
fmt.Println("\nType your LastName of the person you want …Run Code Online (Sandbox Code Playgroud)