May 20, 2016 at 12:57 am
Good day Experts,
How can i save the following script in a powershell file. The script is copied to txt document but i want to change it to .PS 1 file.I tried save as but it is not giving me ps1 option.
Function out-DataTable
{
$dt = new-object Data.datatable
$First = $true
foreach ($item in $input){
$DR = $DT.NewRow()
$Item.PsObject.get_properties() | foreach {
if ($first) {
$Col = new-object Data.DataColumn
$Col.ColumnName = $_.Name.ToString()
$DT.Columns.Add($Col) }
if ($_.value -eq $null) {
$DR.Item($_.Name) = "[empty]"
}
elseif ($_.IsArray) {
$DR.Item($_.Name) =[string]::Join($_.value ,";")
}
else {
$DR.Item($_.Name) = $_.value
}
}
$DT.Rows.Add($DR)
$First = $false
}
return @(,($dt))
}
$hostname = $env:computername
$AfterDate = Get-Date
$dataTable = Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computer $hostname | Select ProviderName, SystemName, DeviceID , VolumeName, Size, FreeSpace | out-DataTable
$connectionString = "Data Source=localhost; Integrated Security=True;Initial Catalog=master;"
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $connectionString
$bulkCopy.DestinationTableName = "dbo.DriveStatus"
$bulkCopy.WriteToServer($dataTable)
May 20, 2016 at 8:31 am
Have you tried using the Powershell ISE to edit and save?
May 20, 2016 at 9:01 am
you are probably using notepad to save your file?
you have to change the file type in the save as dialog.
Change it to all files and enter the extension manually, ie myPowershell.ps1.
Lowell
May 24, 2016 at 6:54 am
Switch text editors to something like Notepad ++ or use the PS ISE.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply