我写了一个简单的脚本,在一定天后删除USMT迁移文件夹:
## Server List ##
$servers = "Delorean","Adelaide","Brisbane","Melbourne","Newcastle","Perth"
## Number of days (-3 is over three days ago) ##
$days = -3
$timelimit = (Get-Date).AddDays($days)
foreach ($server in $servers)
{
$deletedusers = @()
$folders = Get-ChildItem \\$server\USMT$ | where {$_.psiscontainer}
write-host "Checking server : " $server
foreach ($folder in $folders)
{
If ($folder.LastWriteTime -lt $timelimit -And $folder -ne $null)
{
$deletedusers += $folder
Remove-Item -recurse -force $folder.fullname
}
}
write-host "Users deleted : " $deletedusers
write-host
}
Run Code Online (Sandbox Code Playgroud)
但是我一直在畏惧 Remove-Item : …
我有两个PowerShell脚本,它们有switch参数:
编译tool1.ps1:
[CmdletBinding()]
param(
[switch]$VHDL2008
)
Write-Host "VHDL-2008 is enabled: $VHDL2008"
Run Code Online (Sandbox Code Playgroud)
compile.ps1:
[CmdletBinding()]
param(
[switch]$VHDL2008
)
if (-not $VHDL2008)
{ compile-tool1.ps1 }
else
{ compile-tool1.ps1 -VHDL2008 }
Run Code Online (Sandbox Code Playgroud)
如何在不编写大型if..then..else或case语句的情况下将switch参数传递给另一个PowerShell脚本?
我不想在参数转换$VHDL2008的compile-tool1.ps1类型为bool,因为,这两个脚本是前端脚本(由用户使用).后者是多个compile-tool*.ps1脚本的高级包装器.
我在visual studio 11上尝试了一些新的C++ 11功能,从移动构造函数开始.我写了一个名为"MyClass"的简单类,其中包含一个移动构造函数:
class MyClass
{
public:
explicit MyClass( int aiCount )
: mpiSize( new int( aiCount ) ),
miSize2( aiCount)
{
}
MyClass( MyClass&& rcOther )
: mpiSize( rcOther.mpiSize )
, miSize( *rcOther.mpiSize )
{
rcOther.mpiSize = 0;
rcOther.miSize = 0;
}
~MyClass()
{
delete mpiSize;
}
private:
int *mpiSize;
int miSize2;
};
Run Code Online (Sandbox Code Playgroud)
我在这里有问题:
我想在我的脚本中的各个位置输出日期时间以进行日志记录,所以我这样做:
$b = Get-Date
Write-Output "Backups complete at $b"
# more code here
$c = Get-Date
Write-Output "Backups complete at $c"
Run Code Online (Sandbox Code Playgroud)
我不得不使用多个字母表来获取最新的日期/时间.
是否有更简单的方法来执行此操作,或者每次我想再次使用它时是否必须重新建立日期?
我想在一个大目录中搜索一个或几个具有最新修改日期的文件.尝试一些PowerShell代码,但它对我来说效果不佳.
Get-ChildItem 'D:\Temp' | Sort-Object LastWriteTime
Run Code Online (Sandbox Code Playgroud)
我知道我可以-Recurse用来搜索所有目录.但是如何:
限制一些文件
以降序排序
不要列出目录
谢谢你的帮助!
?{ }块在PowerShell中意味着什么?
例如
[enum]::GetValues([io.fileoptions]) | ?{$_.value__ -band 0x90000000}
Run Code Online (Sandbox Code Playgroud) tf:术语"tf"未被识别为cmdlet,函数,脚本文件或可操作程序的名称.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试.
我设置了环境变量但不起作用.tf命令在VS2013的Developer Command Prompt中有效,但在Powershell中不起作用.我怎样才能使这个工作? 在此输入图像描述
在 Mac 上使用 .NET Core 和 Visual Studio Code,我尝试在本地托管 Azure Function,并将调试器附加到它。我可以手动让它工作,方法是使用 启动该函数func host start,然后按 IDE 中的调试按钮,该按钮将运行默认的 launch.json 文件。这让我选择一个进程来附加调试器,因为"processId": "${command:pickProcess}".
我想自动化此流程,只需单击 VSCode 中的调试按钮即可触发它。
在上图中,我尝试通过preLaunchTask在附加调试器之前运行 a 来解决此问题。该任务应该托管并启动该功能 - 当与流程隔离时它会成功完成。但是,当我使用上述配置点击“调试”按钮时,VSCode 让我在实际完成之前选择一个进程preLaunchTask,因此该进程func尚不可用。
我的思路正常吗?为了让它发挥作用,我可能会缺少什么?
azure visual-studio-code azure-functions vscode-tasks vscode-debugger
这是我的代码:
clear-host
function isNumeric ($x) {
try {
0 + $x | Out-Null
return $true
} catch {
return $false
}
}
function output-file ($ave, $high, $low, $date)
{
write-output "Programer: Oday Sawaqed"
write-output "Class: CIS 124"
write-output "PowerShell Assignmnent"
write-output ""
Write-output ""
write-output " Current Date Average Highest Lowest"
write-output " $date $ave $high $low "
}
$array = @()
$hold
$n = 1
do {
$hold = read-host "number $n"
if (isNumeric $hold -eq $true){
if (999 …Run Code Online (Sandbox Code Playgroud) 我试图编写一个ARM模板,用新的静态网站(预览)功能创建一个存储帐户:
当我转到Automation Script刀片时,我在ARM模板中看不到任何相关设置:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccounts_spastore_name": {
"defaultValue": "spastore",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "StorageV2",
"name": "[parameters('storageAccounts_spastore_name')]",
"apiVersion": "2018-02-01",
"location": "westeurope",
"tags": {
"purpose": "example"
},
"scale": null,
"properties": {
"networkAcls": {
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": [],
"defaultAction": "Allow"
},
"supportsHttpsTrafficOnly": false,
"encryption": {
"services": {
"file": {
"enabled": true
},
"blob": {
"enabled": true
}
},
"keySource": "Microsoft.Storage"
}, …Run Code Online (Sandbox Code Playgroud) azure azure-storage azure-storage-blobs azure-resource-manager
powershell ×7
azure ×2
add ×1
arrays ×1
c++ ×1
c++11 ×1
filesystems ×1
limit ×1
tfs ×1
vscode-tasks ×1