powershell - Importing a .csv after prompting for file path for AD account creation in Powershell
问题描述
I'm completely new to scripting and I got thrown into creating an account creator for my company, since the previous employee that did this left.
Currently I have it set to prompt the end user which file they would like to import into the script via the below script.
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFIleDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = $InitialDirectory
$OpenFileDialog.Filter = "CSV (*.csv) | *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
}
$Path = Get-Filename $OpenFileDialog.Filename
This successfully prompts the user which file to use. The issue is after this however. I don't believe it is then importing the file. In my script that I know works, I have it set to a specific file and it then imports that file.
$users = Import-CSV 'filepath'
Any help would be greatly appreciated for this newbie.
解决方案
Which variable are you actually using for the import? This works fine:
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFIleDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = $InitialDirectory
$OpenFileDialog.Filter = "CSV (*.csv) | *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
$Path = $OpenFileDialog.Filename
$MyListOfUsers = Import-CSV -Path $Path
推荐阅读
- css - 为什么媒体类型预计会弃用?
- reactjs - React 和 msal 与 Windows Server AD
- java - 使用工厂模式
- python-3.x - 如何在 Selenium 自动化的 Chrome 扩展屏幕中启用“开发者模式”
- c++ - 输出是 nan 而它不应该是
- c - 可靠地发现 C 编译器是否对所有枚举使用 int
- python - 熊猫数据框:将函数应用于行值和上一行的值
- r - 当 R 中存在空值时,如何拆分包含日期和时间的列?
- c# - Entity Framework Core:外键和引用表 Id 列不匹配
- java - 传递给 Guava Cache get(K key, Callable valueLoader) 的 valueLoader 是否必须是线程安全的才能保证缓存线程安全?