我已經在Windows PowerShell中做了一個創建功能:如何從powershell函數獲取輸出到例如txt的輸出文件中?
function create(){
param(
$searchBase = "OU=Customers,DC=test,DC=nl",
$NewOUs = @(Import-csv -Path $txt_csv.Text -Delimiter ";"),
[switch]$ProtectOU
)
$Protect = $true
If ($ProtectOU){$Protect = $true}
<# ------- CREATE OU ------- #>
foreach ($NewOU in $NewOUs) {
try {
New-ADOrganizationalUnit -Name $NewOU.company -Description $NewOU.description -Path $searchBase -ProtectedFromAccidentalDeletion $Protect
}
catch {
Write-Host "OU already exists"
}
}
$UserList = Import-Csv -Path $txt_csv.Text -Delimiter ";"
<# ------- CREATE USERS ------- #>
foreach ($User in $UserList) {
$OU = $User.path
$UPN = $User.UPN
$Password = $User.password
$Detailedname = $User.firstname + " " + $User.Lastname
$UserFirstname = $User.Firstname
$FirstLetterFirstname = $UserFirstname.substring(0,1)
$SAM = $User.UPN
$Company = $User.company
$Description = $User.description
$AccountExpirationDate = $User.accountexpirationdate
$params = @{ 'Name'=$Detailedname;
'SamAccountName'=$SAM;
'UserPrincipalName'=$UPN+'@test.nl';
'DisplayName'=$Detailedname;
'GivenName'=$UserFirstname;
'Surname'=$User.Lastname;
'AccountPassword'=(ConvertTo-SecureString $Password -AsPlainText -Force);
'Enabled'=$True;
'PasswordNeverExpires'=$True;
'Path'=$OU;
'Company'=$Company;
'Description'=$Description;
'AccountExpirationDate'=$AccountExpirationDate
'HomeDrive' = "H:"
'HomeDirectory' = "\\home\userdata$\$SAM"
'ProfilePath'="\\dc-test\User Profiles$\$SAM"
}
New-ADUser @params
}
我想這個創建功能作爲一個txt例如一個輸出文件。
這是我的WPF按鈕對象:
$button_add.Add_Click({create})
當我點擊按鈕的輸出必須產生一個輸出文件。我已經嘗試了很多這樣的解決方案:
創建|出文件,但我沒有得到的信息,我想:
來源:https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/out-file
是否有可能做到這一點?
親切的問候
但什麼輸出你想要嗎?舉個例子,也許? – 4c74356b41
例如,創建的數據以及創建或失敗的數據。 – Fearcoder