我的脚本将一些信息从 Sharepoint 站点导出到文件中.CSV。
# Enter Web Application URL
$WebAppURL="http://server"
# Enter Path to CSV-file
$CSVFilePath="Path"
$SiteCollections = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All
$Tree = foreach ($Site in $SiteCollections) {
foreach ($Web in $Site.AllWebs) {
$Groups = New-Object System.Collections.ArrayList
foreach ($Group in $web.Groups) {
[void]$Groups.Add($Group.Name)
}
$Groups = $Groups -join ','
[PSCustomObject]@{
Url = $web.URL
Title = $web.Title
CountOfLists= $web.Lists.Count
PermissionsInherited = $web.Permissions.Inherited
Groups = $Groups
}
}
}
$Tree | Export-CSV $CSVFilePath -NoTypeInformation -Encoding UTF8
Run Code Online (Sandbox Code Playgroud)
如果我使用[void] …
我正在尝试创建一个 powershell 脚本,该脚本应使用 Gmail SMTP 服务发送邮件。这是我的 powershell 版本 -
Get-Host | Select-Object Version
Version
-------
5.1.14393.3866
Run Code Online (Sandbox Code Playgroud)
在研究并尝试不同的代码后,我无法通过 Gmail SMTP 从 Powershell 发送电子邮件。这是我的代码:
$emailSmtpServer = "smtp.gmail.com"
$emailSmtpServerPort = "587"
$emailSmtpUser = "mymail@gmail.com"
$emailSmtpPass = "mymailpass"
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = "mymail@gmail.com"
$emailMessage.To.Add("myothermail@mail.com")
$emailMessage.Subject = "Small mail for a friend"
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = @"
<p><strong>Hello me</strong>.</p>
<p>It seems to work</p>
<p>JP</p>
"@
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , …Run Code Online (Sandbox Code Playgroud) 该脚本正确安装了驱动器,但重新启动计算机后驱动器未保留:
\nfunction RemapDrive {\n param( \n $DriveLetter,\n $FullPath,\n $Credential \n )\n \n Write-Host "Trying to remove $DriveLetter in case it already exists ..." \n # $DriveLetter must be concatenated with ":" for the command to work\n net use "${DriveLetter}:" /del\n \n ## $DriveLetter cannot contain ":"\n $psDrive = New-PSDrive -Name "$DriveLetter" -PSProvider "FileSystem" -Root "$FullPath" -Credential $Credential -Scope "Global" -Persist\n \n Write-Host "$DriveLetter was successfully added !" \n}\n\nfunction BuildCredential {\n param (\n $Username,\n $Password\n )\n $pass = ConvertTo-SecureString $Password …Run Code Online (Sandbox Code Playgroud) 节点版本 11.13.0 npm 版本 6.9.0 我已经通过多种方式安装了纱线,首先使用npm install -g yarn,然后我尝试了 .msi 安装程序,我还尝试从提升的 shell 中使用 Chocolatey 安装。通常,当我尝试使用尚未安装的东西时,我会收到如下消息:
PS C:\Users\[me]> hello
hello : The term 'hello' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ hello
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (hello:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)
然而, …
如何从 powershell 连接到 odbc?
我发现了这个功能:
function Get-ODBC-Data{
param(
[string]$query=$('select count(*) from [master].[sys].[table_name]'),
)
$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = "DSN=AllSecure;"
$conn.open()
$cmd = New-object System.Data.Odbc.OdbcCommand($query,$conn)
$ds = New-Object system.Data.DataSet
(New-Object system.Data.odbc.odbcDataAdapter($cmd)).fill($ds) | out-null
$conn.close()
$ds.Tables[0]
}
$result = Get-ODBC-Data
Write-Host "Statistic: " $result[0];
Write-Host "Message: " $result[0] ;
Run Code Online (Sandbox Code Playgroud)
但我还是不知道怎么用!
我应该在哪里提供用户名和密码?
您能给我提供在 Powershell 上运行脚本的命令吗?
或者有更好的连接方式吗?
谢谢!
这确实很基本,但我找不到答案。安装程序设置我的路径,以便我只需键入命令:
服务
在命令提示符处并且脚本运行。我不想等待这个程序完成(毕竟它是一个服务器)。如何从 Powershell 启动相同的脚本(据我所知,这是一个 CMD 脚本),而无需等待它完成(并且无需查找脚本的源目录)?
在经典管道(不是 yaml)中的 Devop 的 powershell 任务中,我尝试将值设置为变量并稍后传递给不同的任务。然而,即使在同一个任务中,我似乎也没有将其设置正确。当我输出它时,它只是空的。我究竟做错了什么?
##vso[task.setvariable variable=NugetVersion]hello-alpha
Write-Host "start";
Write-Host $NugetVersion;
Write-Host $($NugetVersion);
Write-Host "finish";
Run Code Online (Sandbox Code Playgroud) 我正在使用 robocopy 编写一个 powershell 脚本,以从列表中复制“完整”unc/文件名路径。我遇到的问题是 robocopy 似乎\在我的源路径末尾添加了 a 。
我有一个 C:\temp\list.txt,其中列出了带有文件名的 UNC 路径示例:\server\folder\test.txt
我的代码
$Paths = Get-Content -Path C:\Temp\List.txt
ForEach ($p in $Paths) {robocopy $p "\\Server\path\path\"}
The error that powershell is throwing is :
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Monday, March 1, 2021 1:36:52 PM
Source : \\Server\path\path\test.xls\
Dest : \\Server\path\path\
Files : *.*
Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2021/03/01 13:36:52 ERROR 267 (0x0000010B) Accessing Source Directory
\\Server\path\path\test.xls\
The …Run Code Online (Sandbox Code Playgroud) 我想将 csv 文件中的 \ 转义为 \\ 以上传到 Redshift。以下简单的 PowerShell 脚本可以按预期将 $TargetWord \ 替换为 $ReplaceWord \\ ,但使用 bom 导出 utf-8 有时会导致 Redshift 复制错误。
任何改进它的建议将不胜感激。先感谢您。
Param(
[string]$StrExpFile,
[string]$TargetWord,
[string]$ReplaceWord
)
# $(Get-Content "$StrExpFile").replace($TargetWord,$ReplaceWord) | Set-Content -Encoding UTF8 "$StrExpFile"
Run Code Online (Sandbox Code Playgroud) 在 cmd 中,您可以运行C:\path> dir /A,它会列出文件夹中的所有文件(.git/例如,包括隐藏目录)。
您可以dir在 cmd 和 PowerShell 中运行。
可以dir /A在cmd中运行,但不能dir /A在PowerShell中运行。它会抱怨:powershell错误图片
同样,在 PowerShell 中,您可以PS C:\path> ls像在 Linux bash 中一样运行,但不能ls -a像在所有 Linux 中或laUbuntu 中一样运行。
为什么是这样?我的意思是为什么微软要如此部分地实现一些东西?那么如何在 PowerShell 中列出文件夹中的所有文件,例如dir /A在 cmd 或ls -abash 中?
我遇到这种情况是因为我仍在 Windows 7 中运行这些程序还是在 Windows 10 上也是一样?
powershell ×10
azure-devops ×1
cmd ×1
database ×1
gmail ×1
npm-install ×1
odbc ×1
oracle ×1
robocopy ×1
sharepoint ×1
smtp ×1
utf-8 ×1
void ×1
windows-10 ×1
windows-7 ×1
yarnpkg ×1